在Xcode 7中链接静态C库? [英] Linking a Static C Library in Xcode 7?

查看:81
本文介绍了在Xcode 7中链接静态C库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将我创建的静态C库链接到新的Xcode项目.要链接它,我按照以下说明进行操作:

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:

1)导航到构建阶段

2)展开使用库链接二进制文件

3)添加了一个其他"库,然后指定了相关的.a文件.

3) Added an "other" library, and then specified the .a file in question.

不幸的是,该项目无法编译并引发以下错误:

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 Path in 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:

针对您对Eduard Wirch的回答的评论:如果您将-lhdf5替换为-l/full/path/to/libhdf5.a,您也可以仅控制该库的静态链接

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

来自此SO帖子.

但是,我不确定如何执行此操作?我进入了"构建设置",只看到了选项页面,但是标题链接下似乎没有多少内容我做我想做的.

However, I'm not sure how to do this? I've gone into Build Settings and seen nothing but pages of options, but there isn't much under Headers or Linking that seems to allow me to do what I want.

有人可以解释如何正确添加此静态C库吗?仅供参考,相对于库的位置,项目的位置如下:

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:

:/lib/libtxht/libtxht.a Xcode项目: /lib/libtxvm/myProject.xcodeproj

推荐答案

如果这是外部静态库,则需要在构建设置"下将其存在的路径添加到Library Search Paths.不是完整的路径,只是它所在的目录.

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.

这篇关于在Xcode 7中链接静态C库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆