版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
mac应用
在开发mac应用时,需要导入自己的dylib文件,即动态库
就算将dylib导入到工程中,放在工程路径下,仍然会出现
dyld: Library not loaded: /usr/local/lib/xxxx.dylib
Referenced from: /Users/gensee/Library/Developer/Xcode/DerivedData/Training-alpmebybwastnvgsktohhvrnlgin/Build/Products/Debug/Training.app/Contents/MacOS/Training
Reason: image not found
这里的xxxx.dylib已经导入工程中,但xcode还是会在/usr/local/lib/
下寻找,故需要拷贝其到/usr/local/lib/
目录下即可。
还有一种方案即使用install_name_tool
来重新定向
install_name_tool -change [oldpath] [newpath] [target]
install_name_tool -change /usr/local/lib/xxxx.dylib xxx.app/Contents/MacOS/${target}
这样即可处理路径寻找问题。同时如果某个库中相互依赖,也可以使用该命令指定
install_name_tool -change /usr/local/lib/xxx1.dylib @executable_path/xxx1.dylib ${target}.app/Contents/MacOS/xxx2.dylib
这里xxx2.dylib
需要依赖xxx1.dylib
iOS应用
对于iOS应用,导入自己的动态库,需要设置Embedded Binaries
和Mac的问题完全不一样
在这里添加上,然后设置好Framework
的Search Path
就好