为MacOSX构建,但链接针对iOS模拟器文件构建的dylib

我刚刚使用2013年4月15日的命令行工具升级到Xcode 5 beta,并在标准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.co -c /Users/temp/testCCompiler.c lipo -info /Users/temp/testCCompiler.co Non-fat file: testCCompiler.co 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.co -o testCCompiler 

似乎testCCompiler.co和libSystem.dylib都是i386,i386是在link.txt中指定的,而i386是模拟器的正确架构,所以我不确定它为什么认为它是为MacOSX构建的。 也许命令行选项是错误的:(。

谢谢你的帮助!

问题是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.xct oolchain / usr / bin:/ Applications /Xcode5-DP6.app/Contents/Developer/usr/bin:$PATH这些都不是官方的..但到目前为止对我有用。

在你的client.app上运行此评论:

 export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xct‌oolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH