我在xcode工作区中有2个项目。一个是静态库,另一个是静态库。
在静态库中,我添加了GDataXMLNode.h和GDataXMLNode.m文件,我在主项目中使用了这些文件。 GDataXMLNode.h是一个公共文件,因此它在主项目中可见。我还将两个项目的目标与libxml2.dylib相关联。我还在头部搜索路径和用户头搜索路径中包含位置/ usr / include / libxml2。
虽然这些,但我得到了Apple Mach-O Librarian错误:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: can't locate file for: -lxml2
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool failed with exit code 1
你知道我该如何解决这个问题吗?
答案 0 :(得分:9)
我最近遇到了完全相同的错误。如您所见,从构建设置中的“其他链接器标志”中删除“-lxml2”有助于解决错误。在构建静态库时也是如此。您将需要在实际包含静态库的任何目标中包含该链接器标志(“-lxml2”)。例如,如果您像我一样为静态库创建单元测试(即MyStaticLibraryProjectTests),那么您需要确保将链接器标志添加到MyStaticLibraryProjectTests目标,而不是实际的MyStaticLibraryProject目标。通常情况下,当我查看“构建设置”选项卡时,我通常会忘记选择特定目标。我通常认为,如果我点击大蓝项目图标,构建设置仅适用于整个项目,但在修改这些设置时选择正确的目标非常重要。
早期大多数项目通常只有一个目标,但随着您获得更高级,每个项目可能有多个目标。希望有所帮助。