【发布时间】:2013-09-11 23:59:30
【问题描述】:
我刚刚使用 2013 年 4 月 15 日的命令行工具升级到 Xcode 5 测试版,并在标准 CMakeTestCCompiler.cmake 尝试编译一个简单的测试程序期间运行 cmake 构建时遇到以下警告:
cmake -version
cmake version 2.8.11.2
ld: building for MacOSX, but linking against dylib built for iOS Simulator file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libSystem.dylib' for architecture i386
lipo -info /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libSystem.dylib
Non-fat file: libSystem.dylib is architecture: i386
编译步骤为:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -o /Users/temp/testCCompiler.c.o -c /Users/temp/testCCompiler.c
lipo -info /Users/temp/testCCompiler.c.o
Non-fat file: testCCompiler.c.o is architecture: i386
链接步骤是:
/usr/local/bin/cmake -E cmake_link_script /Users/temp/link.txt --verbose=1
link.txt 包含的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -Wl,-headerpad_max_install_names /Users/temp/testCCompiler.c.o -o testCCompiler
似乎 testCCompiler.c.o 和 libSystem.dylib 都是 i386,在 link.txt 中指定了 i386,而 i386 是模拟器的正确架构,所以我不确定它为什么认为它是为 MacOSX 构建的。也许命令行选项是错误的:(。
感谢您的帮助!
【问题讨论】:
-
挖入cmake源码,cmake提交的原始链接命令为:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -Wl,-headerpad_max_install_names /Users/temp/testCCompiler.co -o testCCompiler
-
问题在于 Xcode 5 用 clang 替换了 gcc 并添加了一个“-triple”选项,将 OSX 指定为目标。如果在两个 gcc 命令行上都传递“-miphoneos-version-min=7.0”,它就可以工作。如果将“--verbose”传递给 gcc,则可以看到 clang 命令行。还需要添加到 Xcode 5 的 PATH 以便 cmake 可以找到必要的工具: export PATH=/Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode5 -DP6.app/Contents/Developer/usr/bin:$PATH 这些都不是官方的.. 但到目前为止对我有用。
-
这看起来更像是一个答案而不是评论。
-
@user1031420 请把它作为答案发布,我会投票。
-
嗨@user1031420,我在将Xcode升级到5后也面临这个问题,我几乎尝试了所有提供的解决方案,但没有一个有效。你能详细说明你的解决方案吗?因为我是 Xcode 的新手,所以我无法理解您的解决方案。