1
votes

I'm making a C library for Xcode project, and successfully compiled with -arch armv7, it can be used on iPhone device. Here's the command I used:

./configure \
--host=arm-apple-darwin \
CFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk" \
CXXFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk" \
LDFLAGS="-L." \
CC="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" \
CXX="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"

then make.

I did the same to compile armv7s and arm64 architecture. With -arch i386, I can't use -isysroot with iPhoneOS.platform anymore, I guess because iPhoneOS does not support i386, so I changed to iPhoneSimulator.platform:

./configure \
--host=arm-apple-darwin \
CFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" \
CXXFLAGS="-arch armv7 \
-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" \
LDFLAGS="-L." \
CC="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" \
CXX="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"

But it still does not work. There is the same error when I try to compile i386 with iPhoneOS.platform:

checking whether the C compiler works... no
configure: error: C compiler cannot create executables

It seems that iPhoneSimulator doesn't support i386 too?! When I use armv7 lib for iPhone simulator, it said that missing symbol for i386 architecture, so I'm pretty sure iPhone simulator supports i386.

Anyone know how to compile the lib for simulator? Or is there an easier way, importing source code (like this repo) to Xcode then let it build a universal library for all architectures? From now I must build every lib for every arch then combine them using lipo.

2
After searching for hours, finally I found the solution: Apple replaces gcc with clang in their toolchain and adds in a "-triple" option that specifies OSX as the target. If we add miphoneos-version-min=8.0 (or whatever version you want) to both CFLAGS and CXXFLAGS, then it'll know the target is iOS and let we compile. Make sure to use iPhoneSimulator.platform in -isysroot. - kientux
you should add it as an answer. - sahara108

2 Answers

2
votes

After searching for hours, finally I found the solution: Apple replaces gcc with clang in their toolchain and adds in a "-triple" option that specifies OSX as the target. If we add -miphoneos-version-min=8.0 (or whatever version you want) to both CFLAGS and CXXFLAGS, then it'll know the target is iOS and let we compile. Make sure to use iPhoneSimulator.platform in -isysroot.

0
votes

Try to force the compiler to gcc. Hope that help.

CC="/usr/bin/clang" \
CXX="/usr/bin/clang++"