Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为MacOSX构建,但针对为iOS模拟器文件构建的动态库进行链接_C_Cmake_Clang_Ld - Fatal编程技术网

为MacOSX构建,但针对为iOS模拟器文件构建的动态库进行链接

为MacOSX构建,但针对为iOS模拟器文件构建的动态库进行链接,c,cmake,clang,ld,C,Cmake,Clang,Ld,我刚刚使用2013年4月15日的命令行工具升级到Xcode 5 beta版,并在标准CmaketTestCcompiler.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/

我刚刚使用2013年4月15日的命令行工具升级到Xcode 5 beta版,并在标准CmaketTestCcompiler.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将gcc替换为clang,并添加了一个“-triple”选项,指定OSX为目标。如果在两个gcc命令行上都传递“-miphoneos version min=7.0”,它就可以工作。如果传递“-verbose”,则可以看到clang命令行到gcc。还需要添加到Xcode 5的路径,以便cmake可以找到必要的工具:导出路径=/Applications/Xcode5-DP6.app/Contents/Developer/toolschains/XcodeDefault.xct‌​oolchain/usr/bin:/Applications/Xcode5-DP6.app/Contents/Developer/usr/bin:$PATH这些都不是官方的。但到目前为止对我有效。

在您的客户端上运行此评论。app:

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

深入研究cmake源代码,cmake提交的原始链接命令是:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-arch i386-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.7.0.sdk-Wl,-headerpad\u max\u install\u name/Users/temp/testCCompiler.c.o-o testCCompiler问题在于,Xcode 5用clang替换了gcc,并添加了一个“-triple”选项,将OSX指定为目标。如果在两个gcc命令行上都传递“-miphoneos version min=7.0”,它就会工作。如果传递“-verbose”,则可以看到clang命令行到gcc。还需要添加到Xcode 5的路径中,以便cmake可以找到必要的工具:导出路径=/Applications/Xcode5-DP6.app/Contents/Developer/toolschains/XcodeDefault.xctoolschain/usr/bin:/Applications/Xcode5-DP6.app/Contents/Developer/usr/bin:$PATH这些都不是官方的,但到目前为止对我有效。这看起来更像是一个回复一条评论。@user1031420请将其作为答案发布,我将投票表决。您好@user1031420,我在将Xcode升级到5后也面临这个问题,我几乎尝试了所有提供的解决方案,但没有一个有效。您能详细说明您的解决方案吗?因为我是Xcode新手,我无法理解您的解决方案。