微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

构建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这些都不是官方的..但对我来说至今仍然有效.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐