如何在X $ C $的C 4链接库? [英] How do I link libraries in Xcode 4?

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

问题描述

我是一个完整的初学者到苹果公司的X code,但我也跟着X code文档并没有成功的几个相关问题的咨询。

I'm a complete beginner to Apple's Xcode, but I have followed the Xcode documentation and the advice of a few related questions without success.

我安装 GMP 的到/ usr / local / bin目录,写了使用该库的短节目,并与<编译code> GCC的main.c -lgmp 。它编译没有任何警告或错误,并将可执行完美地工作。

I installed GMP to /usr/local/bin, wrote a short program using the library, and compiled with gcc main.c -lgmp. It compiled with no warnings or errors, and the executable worked flawlessly.

我开始了一个新的X code项目(命令行工具;类型:C),复制code到新建的main.c,打开了项目构建设置。从那里,我设置的链接>其它链接器标记 -lgmp 搜索路径>库搜索路径的/ usr / local / bin目录。然而,构建失败的preprocessor错误Gmp.h:没有这样的文件或目录。

I started a new Xcode project (Command Line Tool; Type: C), copied the code to the newly created main.c, and opened the project build settings. From there I set Linking > Other Linker Flags to -lgmp and Search Paths > Library Search Paths to /usr/local/bin. However, the build fails with the preprocessor error "Gmp.h: No such file or directory".

我已经试过几乎所有可以想象标题:

I have tried almost every header imaginable:

的#includegmp.h

的#include&LT; gmp.h&GT;

的#includeGMP

的#includelibgmp.a。 。

这一直是我的主要障碍在里面有$ P $借鉴C.任何帮助,导致我最终的解决办法是大大AP preciated pvented我的最后三个月。

This has been my main obstacle over the last three months which has prevented me from learning C. Any help leading me to an eventual solution would be greatly appreciated.

推荐答案

有就是你必须建立在你的X code项目的几件事情。例如,我有安装在 /opt/gmp/5.0.2 GMP和我将用它作为例子。实际的库安装到 /opt/gmp/5.0.2/lib 和头文件到 /opt/gmp/5.0.2/include 。当安装库设置的 - preFIX 的标志 /opt/gmp/5.0.2 会自动处理。如果不设置该标志preFIX通常设置为的/ usr /本地默认

There's a few things you have to set up in your Xcode project. For example, I have gmp installed in /opt/gmp/5.0.2 and I will use that as an example. The actual library is installed into /opt/gmp/5.0.2/lib and the header files into /opt/gmp/5.0.2/include. When installing the library setting the --PREFIX flag to /opt/gmp/5.0.2 would handle this automatically. If you don't set this flag the prefix is usually set to /usr/local by default.


  1. 其它链接器标记的期待权,它应该是图书馆的名称。

  2. 搜索头文件应用于包括目录,在我的情况 /opt/gmp/5.0.2/include

  3. 库搜索路径的lib目录,在我的情况 /opt/gmp/5.0.2/lib

  1. The Other Linker Flags looks right, it should be the name of the library.
  2. Set the Header Search Path to the include directory, in my case /opt/gmp/5.0.2/include.
  3. Set the Library Search Path to the lib directory, in my case /opt/gmp/5.0.2/lib.

由于头搜索路径已定,你现在应该能够包括像这样的头文件:

Since the header search path has been set, you should now be able to include the header file like this:

#include <gmp.h>

当然,替换 /opt/gmp/5.0.2 与您在安装GMP您使用preFIX路径。

Of course, replace /opt/gmp/5.0.2 with the PREFIX path you used when you installed gmp.

最后,您通常不安装库的/ usr / local / bin目录,你会安装到的/ usr /本地,让任何二进制文件被安装到仓,而像这些库将被安装到lib中。当然,任何路径方案会的工作,我通常建议的/ opt /&LT;项目名称&gt; /&LT;版本号&GT; ,因为它可以让我更好地跟踪哪些我已经安装并具有相同的库和工具的多个版本,而不必处理冲突。

Lastly, you typically don't install libraries to /usr/local/bin, you would install to /usr/localand let any binaries be installed into bin while libraries like these would be installed into lib. Of course any path scheme would work, I usually recommend /opt/<project-name>/<version-number> since it allows me to keep better track of what I have installed and have multiple versions of the same libraries and tools without having to deal with collisions.

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

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