【问题标题】:iphone - ".../libtool: can't locate file for: -lxml2"iphone - “.../libtool:找不到文件:-lxml2”
【发布时间】:2011-09-20 08:36:46
【问题描述】:

我在 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

你知道我该如何解决这个问题吗?

【问题讨论】:

  • 现在速度很快,尽管我从昨天开始就在尝试。我设法通过从构建设置中删除它来修复它: OTHER_LDFLAGS = "-lxml2";祝你一切顺利!

标签: iphone objective-c ios libxml2


【解决方案1】:

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

大多数项目早期通常只有一个目标,但随着您的进步,每个项目都可能有多个目标。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    相关资源
    最近更新 更多