C++ Xcode 链接器错误:ld:找不到 -twsapi 的库

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

Xcode linker error: ld: library not found for -twsapi

c++xcodelinker

提问by Morten

I have compiled and installed a library using Makefile for i386architecture. The library is located in /usr/local/lib/twsapiand the headers are located in /usr/local/include/twsapi.

我已经使用 Makefile 编译并安装了一个用于i386架构的库。库位于 中/usr/local/lib/twsapi,标题位于/usr/local/include/twsapi.

To use that library in another project I have added libtwsapi.aunder Build Settings > Link Binary With Libraries, and added /usr/local/includeto the HEADER_SEARCH_PATHvariable.

为了在另一个项目中使用该库,我libtwsapi.a在 Build Settings > Link Binary With Libraries 下添加/usr/local/include了该库,并将其添加到HEADER_SEARCH_PATH变量中。

The build process fails during the linking part with the error message ld: library not found for -twsapieven though I have referenced the library. If I remove the link to the binary library I get lots of errors like Undefined symbols for architecture i386:, which makes sense since it cannot find the library in that case. This confirms the library was indeed found in the first place.

ld: library not found for -twsapi即使我已经引用了库,构建过程在链接部分失败并显示错误消息。如果我删除指向二进制库的链接,我会收到很多错误,例如Undefined symbols for architecture i386:,这是有道理的,因为在这种情况下它找不到库。这证实了该库确实是首先被发现的。

Any ideas what's going on? The arguments passed to the linker are shown below:

任何想法发生了什么?传递给链接器的参数如下所示:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ \
  -arch i386 \
  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk \
  -L/Users/morten/Library/Developer/Xcode/DerivedData/test_project-gwzyzroxzbyejngtpizlynumphvo/Build/Products/Debug \
  -L/usr/local/include \
  -L/usr/local/include/twsapi \
  -F/Users/morten/Library/Developer/Xcode/DerivedData/test_project-gwzyzroxzbyejngtpizlynumphvo/Build/Products/Debug \
  -F/usr/local/lib \
  -filelist /Users/morten/Library/Developer/Xcode/DerivedData/test_project-gwzyzroxzbyejngtpizlynumphvo/Build/Intermediates/test_project.build/Debug/test_project.build/Objects-normal/i386/test_project.LinkFileList \
  -mmacosx-version-min=10.9 \
  -stdlib=libc++ \
  -Xlinker \
  -dependency_info \
  -Xlinker /Users/morten/Library/Developer/Xcode/DerivedData/test_project-gwzyzroxzbyejngtpizlynumphvo/Build/Intermediates/test_project.build/Debug/test_project.build/Objects-normal/i386/test_project_dependency_info.dat \
  -o /Users/morten/Library/Developer/Xcode/DerivedData/test_project-gwzyzroxzbyejngtpizlynumphvo/Build/Products/Debug/test_project

回答by rhashimoto

The library is not being found. Your argument that "the library was indeed found in the first place" is faulty because the linker never gets to the point of listing undefined symbols - it halts upon not being able to find all specified libraries.

找不到图书馆。您关于“确实首先找到了库”的论点是错误的,因为链接器永远不会列出未定义的符号 - 它在无法找到所有指定的库时停止。

Your problem is in these arguments to the linker which specify additional paths to search for libraries:

您的问题在于链接器的这些参数指定了搜索库的其他路径:

-L/usr/local/include -L/usr/local/include/twsapi

Note that you are specifying a link path of /usr/local/includeand not /usr/local/libwhich is where your library is.

请注意,您指定的是 /usr/local/ include的链接路径,而不是您的库所在的/usr/local/ lib

You need to add /usr/local/lib to the Library Search Paths in Xcode for linking. The Header Search Paths is used for compiling. From the log it appears that you have entries in both but the Library Search Paths entry is incorrect.

您需要将 /usr/local/lib 添加到 Xcode 中的库搜索路径以进行链接。标题搜索路径用于编译。从日志看来,您在两者中都有条目,但 Library Search Paths 条目不正确。