How do I link libraries in Xcode 4?

六眼飞鱼酱① 提交于 2019-11-30 07:42:07

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. 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>

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

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.

PiotrCh

I have updated my system from snow leopard to mountain lion and had to install gmp.

First of all I have installed Xcode CommandLineTools set.

Secondly, installed Homebrew. Then with it I have done steps in this topic: https://apple.stackexchange.com/questions/38222/how-do-i-install-gcc-via-homebrew

In my last step, made changes to an xcode project as colleague Marcus Karlsson told. It's finally working! Very big Thank You :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!