iOS Compiling (armv7, i386) of several libs. Confi

2019-03-19 09:10发布

问题:

I've been doing a lot of cross-compiling of different libraries for iOS and until iOS5 there was no problem. Ok, apparently my problem is, that the iOS5 SDK does not include the GNU gcc compiler any more. Only llvm and clang are available.

My problem is, that I cannot finish to run the 'configure' script of any library any more. It always fails with:

configure: error: C preprocessor 
"/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" fails sanity check

gcc only is a symbolic link to the llvm compiler. If I set it to clang, it produces the same error. (Just with a nicer syntax error representation)

Here the important part of config.log:

configure:3338: checking how to recognise dependent libraries
configure:3514: result: pass_all
configure:3993: checking how to run the C preprocessor
configure:4111: result: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
configure:4135: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -B/Developer/Platforms/iPhoneOS.platform/Developer/usr -arch armv7 -miphoneos-version-min=5.0 -gdwarf-2 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system conftest.c
conftest.c:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'error'
configure:4141: $? = 1
configure: failed program was:
| /* confdefs.h.  */
| 
| #define PACKAGE_NAME "expat"
| #define PACKAGE_TARNAME "expat"
| #define PACKAGE_VERSION "2.0.1"
| #define PACKAGE_STRING "expat 2.0.1"
| #define PACKAGE_BUGREPORT "expat-bugs@libexpat.org"
| /* end confdefs.h.  */
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
|            Syntax error
configure:4135: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -B/Developer/Platforms/iPhoneOS.platform/Developer/usr -arch armv7 -miphoneos-version-min=5.0 -gdwarf-2 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system conftest.c
conftest.c:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'error'
configure:4141: $? = 1
configure: failed program was:
| /* confdefs.h.  */
| 
| #define PACKAGE_NAME "expat"
| #define PACKAGE_TARNAME "expat"
| #define PACKAGE_VERSION "2.0.1"
| #define PACKAGE_STRING "expat 2.0.1"
| #define PACKAGE_BUGREPORT "expat-bugs@libexpat.org"
| /* end confdefs.h.  */
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
|            Syntax error
configure:4210: error: C preprocessor "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" fails sanity check
See `config.log' for more details.

Here's my environment. A little overkill, but it worked fine with iOS4.X.

# Defines
DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
SDKROOT=$DEVROOT/SDKs/iPhoneOS5.0.sdk

# BUILD STUFF
export CXXFLAGS="-B/Developer/Platforms/iPhoneOS.platform/Developer/usr -arch armv7 -miphoneos-version-min=5.0 -gdwarf-2 -mthumb -isysroot $SDKROOT -L$SDKROOT/usr/lib/system"
export CPPFLAGS="$CXXFLAGS"
export CFLAGS="$CXXFLAGS"
export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
export CXXCPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++
#export CXX=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++
export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
export LD=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld
export RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib
export AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar
export STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip
export LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool
export INSTALL_DIR=/Users/mriedel/MPI/CrossCompiling/armv7_dev_install
export CPATH=$INSTALL_DIR/include
export LIBRARY_PATH=$INSTALL_DIR/lib

I've been trying to figure this out for weeks, but no luck. I feel other people must have come across this problem. But Google did not bring up anything. For a time, I tried to use the gas-preprocessor.pl, but also without any luck.

Ah, my configure calls are always similar to this:

./configure --prefix=$INSTALL_DIR --disable-shared --enable-static --host=arm-apple-darwin

I want to point out that this exact problem happens with all my libraries that use configure scrips. To name a few: apr, apr-util, expat, log4cxx etc... I'm not even sure what the desired output should be. There's just a weirdly placed 'Syntax error' in the middle of the code. No wonder it does not compile :).

Help and tips on how to proceed would be greatly appreciated. Thanks.

回答1:

I ran into the same issue. After some poking, my problem turned out to be that I was setting CPP explicitly. Don't set that (and in fact, 'unset' it if it's set). If it's not set, configure tries $CC -E by default. If it is set, configure doesn't add the -E automatically. Also, setting CPPFLAGS to -E doesn't work, because these flags are also passed to other steps.