如何使用 Xcode 在 C++ 项目中添加静态库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15973472/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:56:39  来源:igfitidea点击:

How to add static libraries inside a C++ project with Xcode

c++xcodestatic-librariesstatic-linking

提问by vdenotaris

I'm developing a C++project by using Xcode4.6.1as IDE. Now, I'd like to add a static library mylib.aand the related header mylib.h.

我正在使用Xcode作为 IDE开发C++项目。现在,我想添加一个静态库和相关的 header 。4.6.1mylib.amylib.h

I read about this solution, but it doesn't work (while clicking on Target Dependencies, the box is still remaining empty).

我阅读了有关此解决方案的信息,但它不起作用(单击Target Dependencies 时,该框仍为空)。

Is there a way to achieve this task?

有没有办法完成这个任务?



UPDATE:

更新:

I created a group, then I added the file mylib.aon it. It seems to work fine, but at compile-time a warning as follows appears:

我创建了一个,然后mylib.a在其上添加了文件。它似乎工作正常,但在编译时出现如下警告:

ld: warning: ignoring file /Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a, file was built for archive which is not the architecture being linked
(i386):/Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a

回答by t.niese

Target dependencies is used if your static library is created by another XCodeproject and you want to include this project, so that you can easily develop on both you library and the corresponding application.

如果您的静态库是由另一个XCode项目创建的,并且您希望包含此项目,则使用目标依赖项,以便您可以轻松地在您的库和相应的应用程序上进行开发。

If you want to include a foreign library you would select your target under TARGETSthere you select the section Build Phasesthere you have the area Link Binary With Librariesinto this area you would add your library either with drag & dropor with the +sign.

如果你想包括一个外国图书馆,你可以在TARGETS下选择你的目标,在那里选择Build Phases部分,在那里你有区域Link Binary With Libraries到这个区域,你可以通过拖放+符号添加你的库。

To add the include path you select your project under PROJECTthere you select the area Build Settingsthere you have under Search Paththe Points Header Search Pathsthis should include the path to the directory where the header is.

要添加包含路径,您在PROJECT下选择您的项目,然后在Search Path下选择Build Settings区域,Points Header Search Paths这应该包括标题所在目录的路径。

The difference between the settings in Projector Targetsis that in Projectit sets the default settings for all targets. In Targetsyou can change the settings per Target.

ProjectTargets 中的设置之间的区别在于,它在Project中为所有目标设置默认设置。在Targets 中,您可以更改每个Target的设置。

EDITFor the linking errors this two answers could be helpful:

编辑对于链接错误,这两个答案可能会有所帮助: