iPhone - ".../libtool: 找不到文件: -lxml2"

3
我在一个xcode工作空间中有两个项目。其中一个是静态库,另一个使用该静态库。
在静态库中,我添加了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

你知道我该怎么修复这个问题吗?


这很快,虽然我昨天就一直在尝试。我通过从构建设置中删除以下内容来解决它:OTHER_LDFLAGS =“-lxml2”;祝你一切顺利! - Bogdan
1个回答

9
我最近也遇到了完全相同的错误。正如你所发现的那样,在构建设置中从“其他链接器标志”中删除“-lxml2”有助于解决这些错误。当您构建静态库时,这是正确的做法。但是,您需要确保在实际包含您的静态库的任何目标中都包括该链接器标志(“-lxml2”)。例如,如果像我一样为您的静态库创建了单元测试(即 MyStaticLibraryProjectTests),则需要确保将链接器标志添加到 MyStaticLibraryProjectTests 目标,而不是实际的 MyStaticLibraryProject 目标。通常情况下,当我查看我的构建设置选项卡时,我往往会忘记选择特定的目标。我通常认为,如果我点击大蓝色项目图标,则构建设置仅适用于整个项目,但是在修改这些设置时选择正确的目标非常重要。

早期大多数项目通常只有一个目标,但是随着您变得更加高级,每个项目可能会有多个目标。希望这有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接