views:

1117

answers:

3

This is a followup to a previous question on cross-compiling for the iPhone:
http://stackoverflow.com/questions/1602182/cross-compile-autotools-based-libraries-for-official-iphone-sdk

Basically, I am trying to compile the Apache Portable Runtime (APR) version 1.3.8 (latest) for the iPhone. I am currently running into the following error during the configuration step:

checking for working PROCESS_SHARED locks... configure: error: in `/Users/michaelsafyan/Downloads/apr-1.3.8':
configure: error: cannot run test program while cross compiling
See `config.log' for more details.

I am invoking the "configure" script via "iphone3.1-configure --disable-dso --enable-threads", where "iphone3.1-configure" is the following script that I've cooked-up to invoke the "configure" script:

#! /bin/bash

#
# Program  : iphone3.1-configure
# Authors  : Michael Aaron Safyan ([email protected])
# Synopsis :
#            This program runs the "configure" script generated by the
#            GNU Autotools in order to cross-compile thirdparty libraries
#            for the iPhone 3.1 SDK. Run this script while in a directory
#            containing an autotools "configure" script. Once you run this,
#            you can use "make" and "sudo make install" to build the library.
#            An install prefix of "/opt/iphone-3.1/" is used.
#

unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset LIBS
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH

export BUILD_DARWIN_VER=`uname -r`
export SDKVER="3.1"
export DEVROOT="/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk"
export PKG_CONFIG_PATH=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$SDKVER.sdk/usr/lib/pkgconfig:/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/pkgconfig:/opt/iphone-$SDKVER/lib/pkgconfig:/usr/local/iphone-$SDKVER/lib/pkgconfig
export PREFIX="/opt/iphone-$SDKVER"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
export CPPFLAGS="-pipe -no-cpp-precomp -I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.2.1/include/ -I$SDKROOT/usr/include -I$DEVROOT/usr/include -I/opt/iphone-$SDKVER/include -I/usr/local/iphone-$SDKVER/include"
export CFLAGS="-std=c99 -arch armv6 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.2.1/include/ -isystem $SDKROOT/usr/include -isystem $DEVROOT/usr/include -isystem /opt/iphone-$SDKVER/include -isystem /usr/local/iphone-$SDKVER/include"
export CXXFLAGS="-std=c99 -arch armv6 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.2.1/include/ -isystem $SDKROOT/usr/include -isystem $DEVROOT/usr/include -isystem /opt/iphone-$SDKVER/include -isystem /usr/local/iphone-$SDKVER/include"
export LDFLAGS="-arch armv6 --sysroot='$SDKROOT' -L$SDKROOT/usr/lib -L$DEVROOT/usr/lib -L/opt/iphone-$SDKVER/lib -L/usr/local/iphone-$SDKVER/lib"
export CPP="$DEVROOT/usr/bin/cpp"
export CXXCPP="$DEVROOT/usr/bin/cpp"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"

if [ ! \( -d "$DEVROOT" \) ] ; then
   echo "The iPhone SDK could not be found. Folder \"$DEVROOT\" does not exist."
   exit 1
fi

if [ ! \( -d "$SDKROOT" \) ] ; then
   echo "The iPhone SDK could not be found. Folder \"$SDKROOT\" does not exist."
   exit 1
fi

./configure --prefix="$PREFIX" --build="i386-apple-darwin$BUILD_DARWIN_VER" --host="arm-apple-darwin9" --enable-static --disable-shared ac_cv_file__dev_zero=no ac_cv_func_setpgrp_void=yes $@

The error that configure is giving me is not the first time I have received a message along the lines of "cannot run test program while cross compiling". In fact, the "ac_cv_file__dev_zero=no" and "ac_cv_func_setpgrp_void=yes" elements in the "iphone3.1-configure" script cause two similarly failing tests to be bypassed. The problem I am having is that I do not know how to bypass this check -- that is, I don't know what variable(s) to set to bypass this test and any additional tests that try to run executables built for the target platform. I was able to bypass the earlier two similar tests simply because I was able to locate the workaround on Google... does anyone know what variables to set or another way to bypass this check?

If anyone knows a way to suppress all tests that cannot be executed when cross-compiling, or if you just know how to suppress this specific check, I would be greatly appreciative. Thank you very much.

+3  A: 

The following variables need to be set:

  • ac_cv_file__dev_zero="yes"
  • ac_cv_func_setpgrp_void="yes"
  • apr_cv_process_shared_works="yes"
  • apr_cv_mutex_robust_shared="no"
  • apr_cv_tcp_nodelay_with_cork="yes"
  • ac_cv_sizeof_struct_iovec="8"
  • apr_cv_mutex_recursive="yes"

Use the following updated "iphone3.1-configure" script to configure the program:

#! /bin/bash

#
# Program  : iphone3.1-configure
# Authors  : Michael Aaron Safyan ([email protected])
# Synopsis :
#            This program runs the "configure" script generated by the
#            GNU Autotools in order to cross-compile thirdparty libraries
#            for the iPhone 3.1 SDK. Run this script while in a directory
#            containing an autotools "configure" script. Once you run this,
#            you can use "make" and "sudo make install" to build the library.
#            An install prefix of "/opt/iphone-3.1/" is used.
#

unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset LIBS
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH

export BUILD_DARWIN_VER=`uname -r`
export SDKVER="3.1"
export DEVROOT="/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk"
export PKG_CONFIG_PATH=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$SDKVER.sdk/usr/lib/pkgconfig:/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/pkgconfig:/opt/iphone-$SDKVER/lib/pkgconfig:/usr/local/iphone-$SDKVER/lib/pkgconfig
export PREFIX="/opt/iphone-$SDKVER"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
export CPPFLAGS="-pipe -no-cpp-precomp -I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.2.1/include/ -I$SDKROOT/usr/include -I$DEVROOT/usr/include -I/opt/iphone-$SDKVER/include -I/usr/local/iphone-$SDKVER/include"
export CFLAGS="-std=c99 -arch armv6 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.2.1/include/ -isystem $SDKROOT/usr/include -isystem $DEVROOT/usr/include -isystem /opt/iphone-$SDKVER/include -isystem /usr/local/iphone-$SDKVER/include"
export CXXFLAGS="-std=c99 -arch armv6 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.2.1/include/ -isystem $SDKROOT/usr/include -isystem $DEVROOT/usr/include -isystem /opt/iphone-$SDKVER/include -isystem /usr/local/iphone-$SDKVER/include"
export LDFLAGS="-arch armv6 --sysroot='$SDKROOT' -L$SDKROOT/usr/lib -L$DEVROOT/usr/lib -L/opt/iphone-$SDKVER/lib -L/usr/local/iphone-$SDKVER/lib"
export CPP="$DEVROOT/usr/bin/cpp"
export CXXCPP="$DEVROOT/usr/bin/cpp"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"

if [ ! \( -d "$DEVROOT" \) ] ; then
   echo "The iPhone SDK could not be found. Folder \"$DEVROOT\" does not exist."
   exit 1
fi

if [ ! \( -d "$SDKROOT" \) ] ; then
   echo "The iPhone SDK could not be found. Folder \"$SDKROOT\" does not exist."
   exit 1
fi

./configure \
    --prefix="$PREFIX" \
    --build="i386-apple-darwin$BUILD_DARWIN_VER" \
    --host="arm-apple-darwin9" \
    --enable-static \
    --disable-shared \
    ac_cv_file__dev_zero="yes" \
    ac_cv_func_setpgrp_void="yes" \
    apr_cv_process_shared_works="yes" \
    apr_cv_mutex_robust_shared="no" \
    apr_cv_tcp_nodelay_with_cork="yes" \
    ac_cv_sizeof_struct_iovec="8" \
    apr_cv_mutex_recursive="yes" $@

Use "iphone3.1-configure --disable-dso --enable-threads && make", then "sudo make install".

Edit

I have provided a more complete solution at Cross-compiling the Apache Portable Runtime for the iPhone.

Michael Aaron Safyan
A: 

Michael I am so interested in building ZipArchive Library using your script are you running this script through the terminal or you're saving it in a file? thanks in advance.

Ahmad Kayyali
Well, this is a little bit old, so I don't know if it will even work any more, but yeah, I save it to a file (e.g. "configure-iphone.sh"), execute "chmod a+x" on the file (e.g. "chmod a+x configure-iphone.sh"), and then run the file from the terminal (e.g. "./configure-iphone.sh"). In any event, good luck.
Michael Aaron Safyan
I should forewarn you that it is generally a good idea to offload the main logic of your application and make it available as a webservice... and then simply have your mobile application act as a thin client to that webservice. That model will lead to the least amount of headache, the greatest amount of portability, etc. I would recommend that over attempting to cross-compile the library (i.e. instead, compile it normally and use it on your server).
Michael Aaron Safyan
A: 

Dear Michael i am so grateful for the reply, i have followed your steps carefully i have used the following command on the terminal:

 ./configure-iphone.sh 

on my library folder path but i am getting the following Errors:

 ./configure-iphone.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf320: command not found
 ./configure-iphone.sh: line 2: syntax error near unexpected token}
 ./configure-iphone.sh: line 2: {\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}

i have seen your web site http://sites.google.com/site/michaelsafyan/coding/articles/iphone/cross-compiling-the-apache-portable-runtime-for-the-iphone and tried to modify the command to

 ./configure-iphone.sh -disable-dso --enable-thread

but also with no luck, to let you know i copied paste your script just modified the SDK version to 4.1, Thanks again.

Ahmad Kayyali
Looks like there might be a copy and paste problem... check the content of the file... it's possible that you've unintentionally included formatting from the website.
Michael Aaron Safyan
Michael thanks for all the support.
Ahmad Kayyali