如何在Xcode中链接动态库? [英] How can I link a dynamic library in Xcode?

查看:223
本文介绍了如何在Xcode中链接动态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Qt中开发一个程序,它使用库libqextserialport.1.dylib.

I am currently developing a program in Qt and it uses the library libqextserialport.1.dylib.

我构建它并以x代码运行,它又吐回来:

I build it and run in x-code and it spits back:

dyld: Library not loaded: libqextserialport.1.dylib
    Referenced from: /Users/samuelreh/Desktop/QtOpenCV/build/Debug/QtOpenCV.app/Contents/MacOS/QtOpenCV
    Reason: image not found

该库位于/Users/samuelreh/Desktop/QtOpenCV/qextserialport/build/.

The library is located in /Users/samuelreh/Desktop/QtOpenCV/qextserialport/build/.

我可以通过以下方法运行我的程序:转到可执行文件文件夹/Users/samuelreh/Desktop/QtOpenCV/build/Debug/QtOpenCV.app/Contents/MacOS/并输入:

I can run my program by changing to the executable folder /Users/samuelreh/Desktop/QtOpenCV/build/Debug/QtOpenCV.app/Contents/MacOS/ and entering:

install_name_tool -change libqextserialport.1.dylib /Users/samuelreh/Desktop/QtOpenCV/qextserialport/build/libqextserialport.1.dylib QtOpenCV

我知道除此之外,可能还有许多解决方案.有人从x代码中知道最好/最优雅/最容易做的事吗?

I know there is probably many solutions besides this. Anybody know the best / most-elegant / easiest to do from x-code?

推荐答案

如果我正确地理解了您的问题,则您的应用程序运行良好,链接时没有错误,但是在尝试启动该库时找不到.

If I understand your problem correctly, your app is building fine, no errors when linking, but when you try to launch it the library cannot be found.

这并不奇怪,因为dylib文件位于系统路径之外的任意目录中.您要么需要将其复制到/usr/lib(可能不是一个好主意),要么将其包含在应用程序包中.后者可能是更好的方法.

That's not surprising, since the dylib file is in some arbitrary directory not on the system path. You either need to copy it into /usr/lib (probably not a good idea) or include it in the application bundle. The latter is probably the better approach.

我从未尝试过,但是显然您需要使用

I've never tried it, but apparently you need to use a Copy Files Build Phase to put the dylib inside your bundle and then configure Xcode so that your executable will know where to find it.

这篇关于如何在Xcode中链接动态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆