简体   繁体   English

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

[英]Linking Mysqllib in static library (MAC OS X.8.4, Xcode 4.6.3)

i´m often using the mysql c api and therefore linking them into my c projects, developed unter xcode. 我经常使用mysql c api,因此将它们链接到我的c项目中,是在xcode上开发的。

Yesterday i tried to build up a static library to encapsulate some db functions. 昨天我试图建立一个静态库来封装一些数据库函数。

But if i try to build the lib there occur some strange errors: 但是,如果我尝试构建库,则会发生一些奇怪的错误:

/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

to include the mysqllib under xcode it is necessary to add the following line to the build set-ip "other linker flags": 为了在xcode下包含mysqllib,必须将以下行添加到build set-ip“ other linker flags”:

-lmysqlclient -lm -lz

As far is i understand xcode is not able to use this linker flags within a static library. 据我了解,xcode不能在静态库中使用此链接器标志。

With a normal command line programm it works fine and i use it since years. 使用正常的命令行程序,它可以正常工作,而且我多年来都在使用它。

Does anyone has a hint for me how to deal with this issue? 有人对我有提示如何处理这个问题吗?

Thanks in advance 提前致谢

solick 酥油

I getting similar error on XCode 5 while replacing old external libraries with newer iOS7-ready version. 在用更新的iOS7就绪版本替换旧的外部库时,在XCode 5上出现类似的错误。

ie:
...can't locate file for: -l
...is not an object file (not allowed in a library)

I discovered Xcode5 incorrectly escaping double-quote while inserting library search path to project.pbxproj . 在将库搜索路径插入project.pbxproj时,我发现Xcode5错误地转义了双引号。

ie: 

incorrect behaviour ---> "\\\"/path/library/\\\"",   (note: 3 slashes)
correct behaviour  ----> "\"/path/library/\"",       (note: 1 slash)

solution

Opening up project.pbxproj and doing a search and replace quickly fixed my problem. 打开project.pbxproj并快速进行搜索和替换解决了我的问题。

ie: search(\\\) replace with (\)

解决了我的问题:在对我有用的主程序中包含了mysql lib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM