如何使用Xcode在C ++项目中添加静态库 [英] How to add static libraries inside a C++ project with Xcode

查看:73
本文介绍了如何使用Xcode在C ++项目中添加静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我阅读了有关 的信息解决方案 ,但不起作用(单击 Target Dependencies (目标依赖项)时,该框仍为空).

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

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

Is there a way to achieve this task?

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

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

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

推荐答案

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

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

如果要包含外部库,则可以在 TARGETS 下选择目标,然后在 Build Phases 部分中选择 Link Binary With图书馆,您可以通过拖动&或带有 + 符号.

If you want to include a foreign library you would select your target under TARGETS there you select the section Build Phases there you have the area Link Binary With Libraries into this area you would add your library either with drag & drop or with the + sign.

要添加包含路径,请在 PROJECT 下选择您的项目,然后在 Search Path 下的Points中选择区域 Build Settings 标题搜索路径,其中应包括标题所在目录的路径.

To add the include path you select your project under PROJECT there you select the area Build Settings there you have under Search Path the Points Header Search Paths this should include the path to the directory where the header is.

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

The difference between the settings in Project or Targets is that in Project it sets the default settings for all targets. In Targets you can change the settings per Target.

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

EDIT For the linking errors this two answers could be helpful:

这篇关于如何使用Xcode在C ++项目中添加静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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