构建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.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,i386在link.txt中指定,而i386是模拟器的正确架构,所以我不知道为什么它认为它是为MacOSX构建的.也许命令行选项是错误的:(.

感谢任何帮助!

解决方法

问题是Xcode 5用clang替换gcc,并添加一个指定OSX作为目标的“-triple”选项.如果您在两个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这些都不是官方的..但对我来说至今仍然有效.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...