【问题标题】:ld: building for tvOS, but linking in object file built for iOS, for architecture arm64ld:为 tvOS 构建,但在为 iOS 构建的目标文件中链接,用于架构 arm64
【发布时间】:2017-11-29 15:06:08
【问题描述】:

我正在为 tvOS 构建一个项目(如果它很重要,目标是一个框架)并从链接器获取错误:

ld:为 tvOS 构建,但在为 iOS 构建的目标文件中链接,用于架构 arm64

我在OBJECTS_FILE_DIR_normal 中运行otool -l *.o 并发现其中一个.o 文件实际上是为iOS 而不是tvOS 构建的。

问题在于该.o 没有对应的源文件(*.mm 或*.cpp)。它被称为<ProjectName>_lto.o,我在构建日志中看不到该文件的任何编译器调用。它在链接器命令行中只出现一次:

-Xlinker -object_path_lto -Xlinker /Full/path/to/<ProjectName>.build/Debug-appletvos/tvOS.build/Objects-normal/arm64/<ProjectName>_lto.o

LLVM_LTO 构建设置未明确设置,但默认为NO。将其显式设置为 NO 无济于事。

我使用的是 Xcode 8.3.2 (8E2002)。

所以我的问题是:为什么要创建这个目标文件,为什么要为错误的目标平台创建它?

【问题讨论】:

    标签: ios xcode linker-errors tvos lto


    【解决方案1】:

    不确定这是否应该是我自己的问题或编辑的答案,因为它没有回答原始问题“为什么会为 LLVM_LTO=NO 的错误拱门生成 _lto.o 文件”,但它可以帮助其他人解决此问题。

    所以我决定在项目中尝试启用 LTO。 LLVM_LTO=YES_THIN 的行为与 LLVM_LTO=NO 相同。 LLVM_LTO=YES 使链接器产生大量警告,如下所示:

    ld: warning: Linking two modules of different target triples: /path/to/one/of/3rdpary/libs/libproblematic.a(file1.o)' is 'arm64-apple-ios7.0.0' whereas 'ld-temp.o' is 'arm64-apple-tvos9.0.0'
    ld: warning: Linking two modules of different target triples: /path/to/one/of/3rdpary/libs/libproblematic.a(file2.o)' is 'arm64-apple-ios7.0.0' whereas 'ld-temp.o' is 'arm64-apple-tvos9.0.0'
    

    但是由于一些奇怪的原因导致所有这些警告链接成功。有趣的是,如果我运行otool -l libproblematic.a,我只会看到cmd LC_VERSION_MIN_TVOS 行而没有cmd LC_VERSION_MIN_IPHONEOS,并且链接器没有抱怨该库中的任何对象是为错误的目标平台构建的。同样file1file2等也不会出现在otool -l libproblematic.a的输出中。

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 2021-12-25
      • 1970-01-01
      • 2021-04-28
      • 2021-01-27
      • 2020-12-15
      • 2021-07-18
      • 2021-01-08
      • 2021-09-24
      相关资源
      最近更新 更多