C++ 在 Xcode 中链接库

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

Linking Libraries in Xcode

c++xcodelinker

提问by Bids

I'm using a powerbook (osx 10.5) and recently downloaded and installed FFTW 3.2 (link text). I've been able to compile and run some simple programs based on the online tutorial using the terminal:

我正在使用 powerbook(osx 10.5),最近下载并安装了 FFTW 3.2(链接文本)。我已经能够使用终端根据在线教程编译和运行一些简单的程序:

g++ main.cpp -lfftw3 -lm

However, I can't get the same program to compile in Xcode. I get a linking error, "symbol(s) not found". There is a file called libfftw3.a in /usr/local/lib. How can this be linked? Furthermore, apparently the libraries have to be linked in a particular order, i.e. see: link text

但是,我无法在 Xcode 中编译相同的程序。我收到链接错误,“找不到符号”。/usr/local/lib 中有一个名为 libfftw3.a 的文件。这怎么能联系起来?此外,显然必须以特定顺序链接库,即请参阅:链接文本

thanks for any help

谢谢你的帮助

回答by Bids

To link to a .a library like this in Xcode you need to:

要在 Xcode 中链接到这样的 .a 库,您需要:

  • Double-click on your target or application in Xcode to open the Info window

  • Switch to the "Build" tab

  • Add -lfftw3 to "Other Linker Flags" (under "Linking")

  • Add the path to your library to the "Library Search Paths" (under "Search Paths"). In your case this will be /usr/local/lib

  • 在 Xcode 中双击您的目标或应用程序以打开信息窗口

  • 切换到“构建”选项卡

  • 将 -lfftw3 添加到“其他链接器标志”(在“链接”下)

  • 将图书馆的路径添加到“图书馆搜索路径”(在“搜索路径”下)。在您的情况下,这将是 /usr/local/lib

We use FFTW (it's great by the way), this works for us!

我们使用 FFTW(顺便说一下它很棒),这对我们有用!

回答by robottobor

Did you set these options for the target?

您是否为目标设置了这些选项?

Under "Linking->Other Linker Flags" add: "-L/path/to/library -lfftw3 -lm"

在“链接->其他链接器标志”下添加:“-L/path/to/library -lfftw3 -lm”

回答by Gabor Forgacs

warning in /Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libfftw3.a, file is not of required architecture

/Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libfftw3.a 中的警告,文件不是必需的架构

Maybe the binary format was different e.g. the library could be 32 bit while the application 64.

也许二进制格式不同,例如库可能是 32 位,而应用程序可能是 64 位。

回答by Gabor Forgacs

OK - I finally got this working. I also needed the the GNU Scientific Libraries and ran into similar issues with the architecture setting. For anyone interested, this tutorial goes through how to set up Xcode and link libraries:

好的 - 我终于开始工作了。我还需要 GNU 科学图书馆,并在架构设置方面遇到了类似的问题。对于任何感兴趣的人,本教程将介绍如何设置 Xcode 和链接库:

https://web.archive.org/web/20101006023300/http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31

https://web.archive.org/web/20101006023300/http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31