我经常使用 mysql c api,因此将它们链接到我的 c 项目中,由 xcode 开发。
昨天我尝试构建一个静态库来封装一些数据库函数。
但是如果我尝试构建库,就会发生一些奇怪的错误:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lm
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lm is not an object file (not allowed in a library)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lz
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lz is not an object file (not allowed in a library)
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1
要在 xcode 下包含 mysqllib,需要将以下行添加到构建 set-ip“其他链接器标志”:
-lmysqlclient -lm -lz
据我了解,xcode 无法在静态库中使用此链接器标志。
使用普通的命令行程序,它可以正常工作,我已经使用它很多年了。
有人告诉我如何处理这个问题吗?
提前致谢
索力克
最佳答案
当我用更新的 iOS7 版本替换旧的外部库时,我在 XCode 5 上遇到类似的错误。
ie:
...can't locate file for: -l
...is not an object file (not allowed in a library)
我发现 Xcode5 在将库搜索路径插入到 project.pbxproj 时错误地转义了双引号。
ie:
incorrect behaviour ---> "\\\"/path/library/\\\"", (note: 3 slashes)
correct behaviour ----> "\"/path/library/\"", (note: 1 slash)
解决方案
打开project.pbxproj并进行搜索和替换很快解决了我的问题。
ie: search(\\\) replace with (\)
关于mysql - 在静态库中链接 Mysqllib (MAC OS X.8.4, Xcode 4.6.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18373589/