Why is building helloworld for iOS not easy from command line?

The code, it doesn't get much simplier than this


#include <stdio.h>
main( )
{
printf("hello, world\n");
return 0;
}


specify a compiler


CC="$(xcrun --sdk iphoneos --find clang) -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch arm64"


command line equivalent of $CC hello.c

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -arch arm64 hello.c


bomb

clang: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX' [-Wincompatible-sysroot]


ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a, missing required architecture arm64 in file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a (3 slices)
ld: building for OSX, but linking against dylib built for iOS (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/usr/lib/libSystem.tbd). file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/usr/lib/libSystem.tbd' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


no where did i target macosx, in face the correct sdk was specified in TWO places

Accepted Reply

I finally managed to beat Xcode into submission and found several bugs while doing so.


In the end, apple clang wrapper for gcc is unstable a.k.a. broken.

Replies

I finally managed to beat Xcode into submission and found several bugs while doing so.


In the end, apple clang wrapper for gcc is unstable a.k.a. broken.

If so, don't hesitate ti file bug reports.

Would you mind sharing how you solved the problem ? Having the same issue here...

The bash script I used is too complicated to post.


To beat Xcode into submission, in a nutshell this is what I did.


Key 1 You need create a clean shell env, bash, csh, etc that does not pick up any login or nothing from /usr/local or /opt/local for macports , so PATH has bare minimum for functioning shell; /bin, /sbin, /usr/bin, /usr/sbin, no LDFLAGS, CPPFLAGS, CFLAGS, CC, CPP, CXX, CPATH, etc.


Key 2 Xcode has to be in the default location with default name under /Applications.


Key 3 When you specificy a compiler, include sysroot as an env var, CC="/usr/bin/clang -isysroot=${SYSROOT}", i already defined SYSROOT, this is defined by what you're building iphoneos, iphonesimulator, etc. do same for CXX, CPP, define isysroot with compilers.


If you don't join the string, the build will usually fail, this will fail CC="/usr/bin/clang" -isysroot="${SYSROOT}",


If you just pass a '*****' compiler like CC='/usr/bin/clang', clang randomly chokes depending upon which framework is linked. If you use CC='/usr/bin/gcc', it can find frameworks most of the time but I still passed isysroot. /usr/bin/clang++ worked "most "of the time, no rhyme or reason. If there is a configure in the source code, pass it sysroot as well if needed, ex; --with-sysroot=${SYSROOT} or configure --help to dump out env vars


I was able to build the bleeding edge versions from github with the latest PRs of openssl, pcre2, flac, ffmpeg, vorbis, x265/x264 into static libs/frameworks for all platforms I needed, devices and simulators.