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

蹲街弑〆低调 提交于 2019-12-24 10:41:49

问题


I have compiled and installed a library using Makefile for i386 architecture. The library is located in /usr/local/lib/twsapi and the headers are located in /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/include to the HEADER_SEARCH_PATH variable.

The build process fails during the linking part with the error message ld: library not found for -twsapi even 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.

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

回答1:


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/include and not /usr/local/lib which is where your library is.

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.



来源:https://stackoverflow.com/questions/24267730/xcode-linker-error-ld-library-not-found-for-twsapi

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