在 Xcode 7 中链接静态 C 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39648816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking a Static C Library in Xcode 7?
提问by Micrified
I'm currently trying to link a static C library I've created to a fresh Xcode project. To link it, I followed the following instructions:
我目前正在尝试将我创建的静态 C 库链接到一个新的 Xcode 项目。为了链接它,我遵循了以下说明:
1) Navigate to Build Phases
1) 导航到构建阶段
2) Expand Link Binaries With Library
2)用库扩展链接二进制文件
3) Added an "other" library, and then specified the .a file in question.
3) 添加了“其他”库,然后指定了有问题的 .a 文件。
Unfortunately, the project won't compile and throws the following error:
不幸的是,该项目不会编译并引发以下错误:
ld: library not found for -ltxht
I'm not sure exactly what to make of this. The library seems to appear okay in the project as a project file, and I can't find any indication that there is anything wrong with that.
我不确定该怎么做。该库在项目中作为项目文件似乎没问题,我找不到任何迹象表明这有什么问题。
I've tried setting it's location to Use Absolute Pathin the file-inspector, but that didn't change anything.
我试过在文件检查器中将它的位置设置为使用绝对路径,但这并没有改变任何东西。
I've also seen that in some similar online posts that somehow providing the full path to the static library might help resolve the problem:
我还看到在一些类似的在线帖子中,以某种方式提供静态库的完整路径可能有助于解决问题:
In reaction to your comment on Eduard Wirch' answer: you can also control static linking for this one library only, if you replace -lhdf5 by -l/full/path/to/libhdf5.a
回应您对 Eduard Wirch 回答的评论:如果您将 -lhdf5 替换为 -l/full/path/to/libhdf5.a,您还可以仅控制该库的静态链接
From this SO Post.
However, I'm not sure how to do this? I've gone into Build Settingsand seen nothing but pages of options, but there isn't much under Headersor Linkingthat seems to allow me to do what I want.
但是,我不确定如何执行此操作?我已经进入构建设置,除了选项页面之外什么也没看到,但是标题或链接下似乎没有太多内容可以让我做我想做的事。
Can anyone explain how to correctly add this static C library? Just for your information, the location of the project relative to the location of the library is as follows:
谁能解释一下如何正确添加这个静态 C 库?仅供参考,项目相对于库位置的位置如下:
Library:/lib/libtxht/libtxht.a
Xcode Project:/lib/libtxvm/myProject.xcodeproj
库:/lib/libtxht/libtxht.a
Xcode 项目:/lib/libtxvm/myProject.xcodeproj
采纳答案by Mobile Ben
If this is an external static lib, you need to add the path it exists to Library Search Paths
under Build Settings. Not the full path, just the directory it is in.
如果这是一个外部静态库,则需要Library Search Paths
在 Build Settings 下添加它存在的路径。不是完整路径,只是它所在的目录。