为什么在我的 Mac 应用程序中出现 link 错误(未定义的符号),因为引用已经在静态库中成功构建并 linked?

Why link errors (Undefined symbols) in my Mac app for references that already built and linked successfully in the static library?

我的应用程序使用了一个库,我也有源代码并成功构建。该库使用了一些源代码,从 zxing 到很清楚,它再次发现并解析了所有函数调用。但是当我使用这个库时,我遇到了一些指向那些 zxing 引用的链接器错误(未定义的符号)。似乎不可能,因为该应用程序对该代码一无所知——它被隐藏在库中。如何解决这些错误?

来自Xcode:

Ld DerivedData2/ailhost/Build/Products/Release/ailhost.app/Contents/MacOS/ailhost normal x86_64
    cd /Users/me1/Documents/ailhost_mac/svn/trunk/ailhost
    export MACOSX_DEPLOYMENT_TARGET=10.10
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/me1/Documents/ailhost_mac/svn/trunk/ailhost/DerivedData2/ailhost/Build/Products/Release -L/Users/me1/Documents/ailhost_mac/svn/trunk/ailhost/ailhost -F/Users/me1/Documents/ailhost_mac/svn/trunk/ailhost/DerivedData2/ailhost/Build/Products/Release -filelist /Users/me1/Documents/ailhost_mac/svn/trunk/ailhost/DerivedData2/ailhost/Build/Intermediates/ailhost.build/Release/ailhost.build/Objects-normal/x86_64/ailhost.LinkFileList -Xlinker -rpath -Xlinker @executable_path/../Frameworks -mmacosx-version-min=10.10 -stdlib=libstdc++ -fobjc-arc -fobjc-link-runtime -lboost_system-mt -lboost_thread-mt -lSLABHIDtoUART -framework Accelerate -lProcessor -Xlinker -dependency_info -Xlinker /Users/me1/Documents/ailhost_mac/svn/trunk/ailhost/DerivedData2/ailhost/Build/Intermediates/ailhost.build/Release/ailhost.build/Objects-normal/x86_64/ailhost_dependency_info.dat -o /Users/me1/Documents/ailhost_mac/svn/trunk/ailhost/DerivedData2/ailhost/Build/Products/Release/ailhost.app/Contents/MacOS/ailhost

Undefined symbols for architecture x86_64:
  "zxing::DecodeHints::DecodeHints()", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::BinaryBitmap::BinaryBitmap(zxing::Ref<zxing::Binarizer>)", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::HybridBinarizer::HybridBinarizer(zxing::Ref<zxing::LuminanceSource>)", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::GreyscaleLuminanceSource::GreyscaleLuminanceSource(zxing::ArrayRef<char>, int, int, int, int, int, int)", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::Result::getResultPoints()", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::Result::getText()", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::qrcode::QRCodeReader::QRCodeReader()", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
  "zxing::Exception::deleteMessage()", referenced from:
      zxing::Exception::~Exception() in libProcessor.a(Processor.o)
  "zxing::Exception::copy(char const*)", referenced from:
      zxing::Exception::Exception(zxing::Exception const&) in libProcessor.a(Processor.o)
  "zxing::String::getText() const", referenced from:
      Processor::processQRCodeInternal(int, int, int, int) in libProcessor.a(Processor.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

已修复。问题是 zxing 文件夹中的文件没有被编译到库中,因为文件夹 ("zxing") 和任何文件都不是目标的一部分。我通过仔细检查 "Build Settings" 下的 "Compile Sources" 验证了这一点。 (令人恼火的是,当你构建一个静态库时,当文件实际上 not 内置到生成的二进制文件中时,它不会向你显示任何编译错误。)为了我温和的读者的利益,这是怎么发生的是当我右键单击 Xcode 中的主项目文件夹并选择 "Add files to ..." 然后浏览并选择具有所需源的文件夹 ("zxing") 我按原样使用设置, "Create folder references" 被选中。我删除了文件夹然后重新添加,但第二次选择了 "Create Groups"(见附图)。瞧!根据需要将文件添加到目标中。然后构建静态库时没有问题(和以前一样)只有当我实际将我的应用程序 link 放到库中时我才没有未定义的符号错误。