【问题标题】:error: target Objective-C runtime differs in PCH file vs. current file错误:目标 Objective-C 运行时在 PCH 文件与当前文件中不同
【发布时间】:2021-06-18 18:43:46
【问题描述】:

我正在尝试使用命令行(由CMake 生成)为Catalyst 编译Objective-C 或.m 文件,但遇到两个编译错误!

1。每当我使用以下标志之一启用 Catalyst 时:

-target x86_64-apple-ios-macabi
-target x86_64-apple-ios13.0-macabi
-target x86_64-apple-ios13.5-macabi
-target x86_64-apple-ios13.7-macabi

2。然后强制重建(点击Clean Build Folder,然后点击Build)。

3。构建失败并出现错误:

fatal error: 'UIKit/UIKit.h' file not found

4。但是一旦我切换到13.6,我的意思是,将标志更改为:

-target x86_64-apple-ios13.6-macabi

5。然后强制重建,我得到一个新的错误:

error: target Objective-C runtime differs in PCH file vs. current file

请注意,我没有使用任何 PCH 文件,而且这两个错误似乎完全令人困惑。

另外,我搜索并找到了post similar to second error,但建议的修复(即切换到13.6)是导致第二个错误的原因。 (应该修复它,但正在触发它)。

【问题讨论】:

    标签: objective-c cmake clang mac-catalyst


    【解决方案1】:

    在捕获 Xcode 的完整命令行后,我注意到它有 -x objective-c 标志,而我的 CMake 没有!

    搜索后(关于how CMake support's Obj-C), 发现实际错误!

    1。基本上,CMake 需要我做类似的事情:

    project(MyProject C CXX OBJC OBJCXX)
    

    代替:

    project(MyProject)
    

    2。另外,应该将 Obj-C 标志添加到 CMAKE_OBJC_FLAGS 而不是 CMAKE_C_LINK_FLAGS 变量中。

    3。现在 CMake 会自动添加缺少的 -x objective-c 标志,我只需要添加我的自定义标志。


    完整的 Xcode 命令行:

    -x objective-c -target x86_64-apple-ios13.6-macabi -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fobjc-arc -fmodules -gmodules -fmodules-cache-path=/Users/admin/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/admin/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -fmodule-name=MyProject -fapplication-extension -fpascal-strings -O0 -fno-common -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -g -fprofile-instr-generate -fcoverage-mapping -index-store-path /MyBuildDir/Index/DataStore -iquote /MyBuildDir-cofig/MyProject-generated-files.hmap -I/MyBuildDir-cofig/MyProject-own-target-headers.hmap -I/MyBuildDir-cofig/MyProject-all-non-framework-target-headers.hmap -ivfsoverlay /MyBuildDir-cofig/all-product-headers.yaml -iquote /MyBuildDir-cofig/MyProject-project-headers.hmap -I/MyProductDir/include -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/iOSSupport/usr/include -I/MyBuildDir-cofig/DerivedSources-normal/x86_64 -I/MyBuildDir-cofig/DerivedSources/x86_64 -I/MyBuildDir-cofig/DerivedSources -F/MyProductDir -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/iOSSupport/System/Library/Frameworks -MMD -MT dependencies -MF /MyBuildDir-cofig/Objects-normal/x86_64/my-source.d --serialize-diagnostics /MyBuildDir-cofig/Objects-normal/x86_64/my-source.dia -c /Users/admin/my-project/my-source.m -o /MyBuildDir-cofig/Objects-normal/x86_64/my-source.o
    

    注意,我在上面替换了要缩短的路径,例如:

    MyBuildDir        => /Users/admin/Library/Developer/Xcode/DerivedData/MyProject-gczfeuobxydqjrfbdhwzpqjsseyr
    
    MyBuildDir-config => /Users/admin/Library/Developer/Xcode/DerivedData/MyProject-gczfeuobxydqjrfbdhwzpqjsseyr/Build/Intermediates.noindex/MyProject.build/Debug-maccatalyst/MyProject.build/
    
    MyProductDir      => /Users/admin/Library/Developer/Xcode/DerivedData/MyProject-gczfeuobxydqjrfbdhwzpqjsseyr/Build/Products/Debug-maccatalyst
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多