11

I've just upgraded to Xcode 5 beta with the April 15 2013 commandline tools and hit the following warning when running a cmake build during the standard CMakeTestCCompiler.cmake attempt to compile a simple test program:

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

The compile step is:

/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

The link step is:

/usr/local/bin/cmake -E cmake_link_script /Users/temp/link.txt --verbose=1

where link.txt contains:

/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

It seems that both testCCompiler.c.o and libSystem.dylib are i386, i386 is specified in link.txt, and i386 is the right architecture for the simulator so i'm not sure why it thinks it is building for MacOSX. Perhaps a commandline option is wrong :(.

thanks for any help!

jww
  • 97,681
  • 90
  • 411
  • 885
user1031420
  • 505
  • 1
  • 5
  • 13
  • 1
    Dug into the cmake source and the raw link command submitted by cmake is: /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 – user1031420 Sep 08 '13 at 18:39
  • 4
    The problem was that Xcode 5 replaces gcc with clang and adds in a "-triple" option that specifies OSX as the target. If you pass "-miphoneos-version-min=7.0" on both gcc command lines it works. You can see the clang command line if you pass "--verbose" to gcc. It's also necessary to add to the PATH for Xcode 5 so that cmake can find the necessary tools: export PATH=/Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode5-DP6.app/Contents/Developer/usr/bin:$PATH None of this is official.. but works for me so far. – user1031420 Sep 09 '13 at 00:08
  • 1
    That looks more like an answer than a comment. – rjmunro Oct 01 '13 at 08:53
  • @user1031420 please, post it as answer, i will vote it. – user170317 Oct 06 '13 at 10:05
  • 1
    Hi @user1031420, I am also facing this problem after upgrading Xcode to 5, I almost tried all solutions provided but none of them worked. Could you elaborate your solution? since I am new to Xcode I am not able to understand your solution. – xrnd Oct 10 '13 at 10:30
  • ok.. posted as answer. Regrettably i'm a bit pressed for time, xmd, but if you're working at this level the time you spend understanding the underlying compiler/linker options won't be wasted. Alternatively, if you can afford to wait, the cmake/Xcode 5 kinks will be worked out. – user1031420 Oct 21 '13 at 22:01
  • possible duplicate of [Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS](http://stackoverflow.com/questions/7173626/apple-mach-o-linker-id-warning-building-for-macosx-but-linking-against-dyli) – jww Jan 22 '15 at 02:21

2 Answers2

24

The problem was that Xcode 5 replaces gcc with clang and adds in a "-triple" option that specifies OSX as the target. If you pass "-miphoneos-version-min=7.0" on both gcc command lines it works. You can see the clang command line if you pass "--verbose" to gcc. It's also necessary to add to the PATH for Xcode 5 so that cmake can find the necessary tools: export PATH=/Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xct‌​oolchain/usr/bin:/Applications/Xcode5-DP6.app/Contents/Developer/usr/bin:$PATH None of this is official.. but works for me so far.

user1031420
  • 505
  • 1
  • 5
  • 13
1

run this comment on your client.app:

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xct‌oolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
demongolem
  • 9,474
  • 36
  • 90
  • 105
ChenYilong
  • 8,543
  • 9
  • 56
  • 84