mysql - 在静态库中链接 Mysqllib (MAC OS X.8.4, Xcode 4.6.3)

标签 mysql c xcode macos api

我经常使用 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/

相关文章:

mysql - 查找一天内访问该网址的用户数

c - 连续录制音频的内存问题

objective-c - 如何判断用户何时点击 UITableViewCell?

c++ - 是否可以修改内存中的函数?

c++ - 如何使用 OpenCV 中可用的压缩算法?

objective-c - 为什么 ((self=[super init]]) 有效,但 (!(self=[super init])) 无效?

objective-c - iOS 3.x 上的自动引用计数

mysql - SQL 语句 - SQL 矩阵

php - PHP 中选择元素的默认值

sql - 如何在时间排序表中查找间隙,其中给定列在指定间隔内没有特定值