cross-compiling for iPhone dev
2011-08-28 15:33
302 查看
http://robertcarlsen.net/2009/07/15/cross-compiling-for-iphone-dev-884
Update: Proof-of-concept
demo. Also, updated the script for building with the 10.6 SDK.
Update #2: Source code for demo project
released.
Update #3: script for use with tesseract v3
posted.
I recently had need to use an open-source library in an iPhone project. Recalling the earlier work necessary incompiling the libraries needed foropenFrameworks
I started looking for a more generic way to build for iPhone development. Thankfully, LateNiteSoft wrote a greatarticle about using a shell script to cross-compile
linux projects, building a Universal Binary with versions for the Simulator and Device.
I configured their provided code snippets to build tesseract-ocr for iPhone, referring to the set-up for freetype and freeimage to fill in some c++ gaps. Anyway, the library seems to have built correctly. I’ll know for sure when I incorporate it into a project,
soon.
To use it, copy the script into the project directory, next to the configure script. For a simple project which generates one monolithic library, edit the LIBFILE variable to reflect the location and name of the library. I’ve only used this for static libraries…other
work may be necessary to correctly generate dynamic libraries (however, the iPhone SDK prohibits linking to dynamic libraries, so in this case it seems moot). Run ./build_fat.sh to kick off the process. Look for the compiled libraries in the “lnsout” directory.
There’s no error checking, so caveat emptor. :)
Cross-compile shell script follows:
For reference, here is the original script (written for use with 10.5):
Update: Proof-of-concept
demo. Also, updated the script for building with the 10.6 SDK.
Update #2: Source code for demo project
released.
Update #3: script for use with tesseract v3
posted.
I recently had need to use an open-source library in an iPhone project. Recalling the earlier work necessary incompiling the libraries needed foropenFrameworks
I started looking for a more generic way to build for iPhone development. Thankfully, LateNiteSoft wrote a greatarticle about using a shell script to cross-compile
linux projects, building a Universal Binary with versions for the Simulator and Device.
I configured their provided code snippets to build tesseract-ocr for iPhone, referring to the set-up for freetype and freeimage to fill in some c++ gaps. Anyway, the library seems to have built correctly. I’ll know for sure when I incorporate it into a project,
soon.
To use it, copy the script into the project directory, next to the configure script. For a simple project which generates one monolithic library, edit the LIBFILE variable to reflect the location and name of the library. I’ve only used this for static libraries…other
work may be necessary to correctly generate dynamic libraries (however, the iPhone SDK prohibits linking to dynamic libraries, so in this case it seems moot). Run ./build_fat.sh to kick off the process. Look for the compiled libraries in the “lnsout” directory.
There’s no error checking, so caveat emptor. :)
Cross-compile shell script follows:
#!/bin/sh # build_fat.sh # # Created by Robert Carlsen on 15.07.2009. # Updated 6.12.2009 to build i386 (simulator) on an x86_64 platform (10.6 SDK) # build an arm / i386 lib of standard linux project # # adopted from: #http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.htm # # initially configured for tesseract-ocr # Set up the target lib file / path # easiest to just build the package normally first and watch where the files are created. LIBFILE=ccmain/libtesseract_full # Select the desired iPhone SDK export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.0.sdk # Set up relevant environment variables export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/ -miphoneos-version-min=2.2" export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT" export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS" export CXXFLAGS="$CFLAGS" # Dynamic library location generated by the Unix package LIBPATH=$LIBFILE.dylib LIBNAME=`basename $LIBPATH` export LDFLAGS="-L$SDKROOT/usr/lib/ -Wl,-dylib_install_name,@executable_path/$LIBNAME" # Static library that will be generated for ARM LIBPATH_static=$LIBFILE.a LIBNAME_static=`basename $LIBPATH_static` # TODO: add custom flags as necessary for package ./configure CXX=$DEVROOT/usr/bin/arm-apple-darwin9-g++-4.0.1 CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin make -j4 # Copy the ARM library to a temporary location mkdir -p lnsout cp $LIBPATH_static lnsout/$LIBNAME_static.arm # Do it all again for native cpu make distclean # Restore default environment variables unset CPPFLAGS CFLAGS CPP LDFLAGS CXXFLAGS DEVROOT SDKROOT export DEVROOT=/Developer export SDKROOT=$DEVROOT/SDKs/MacOSX10.6.sdk export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/i686-apple-darwin10/4.0.1/include/ -I$SDKROOT/usr/include/ -mmacosx-version-min=10.5" export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT -arch i386" export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS" export CXXFLAGS="$CFLAGS" #Overwrite LDFLAGS # Dynamic linking, relative to executable_path # Use otool -D to check the install name export LDFLAGS="-Wl,-dylib_install_name,@executable_path/$LIBNAME" # TODO: error checking ./configure make -j4 # Copy the native library to the temporary location cp $LIBPATH_static lnsout/$LIBNAME_static.i386 # Create fat lib by combining the two versions /usr/bin/lipo -arch arm lnsout/$LIBNAME_static.arm -arch i386 lnsout/$LIBNAME_static.i386 -create -output lnsout/$LIBNAME_static unset CPPFLAGS CFLAGS CPP LDFLAGS CPP CXXFLAGS DEVROOT SDKROOT
For reference, here is the original script (written for use with 10.5):
#!/bin/sh # build_fat.sh # # Created by Robert Carlsen on 15.07.2009. # build an arm / i686 lib of standard linux project # # adopted from: # http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html # # initially configured for tesseract-ocr # Set up the target lib file / path # easiest to just build the package normally first and watch where the files are created. LIBFILE=ccmain/libtesseract_full # Select the desired iPhone SDK export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer export SDKROOT=$DEVROOT/SDKs/iPhoneOS2.2.sdk # Set up relevant environment variables export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/" export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT" export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS" export CXXFLAGS="$CFLAGS" # Dynamic library location generated by the Unix package LIBPATH=$LIBFILE.dylib LIBNAME=`basename $LIBPATH` export LDFLAGS="-L$SDKROOT/usr/lib/ -Wl,-dylib_install_name,@executable_path/$LIBNAME" # Static library that will be generated for ARM LIBPATH_static=$LIBFILE.a LIBNAME_static=`basename $LIBPATH_static` # TODO: add custom flags as necessary for package ./configure CXX=$DEVROOT/usr/bin/arm-apple-darwin9-g++-4.0.1 CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin make -j4 # Copy the ARM library to a temporary location mkdir -p lnsout cp $LIBPATH_static lnsout/$LIBNAME_static.arm # Do it all again for native cpu make distclean # Restore default environment variables unset CPPFLAGS CFLAGS CPP LDFLAGS CXXFLAGS # Overwrite LDFLAGS # Dynamic linking, relative to executable_path # Use otool -D to check the install name export LDFLAGS="-Wl,-dylib_install_name,@executable_path/$LIBNAME" # TODO: error checking ./configure make -j4 # Copy the native library to the temporary location cp $LIBPATH_static lnsout/$LIBNAME_static.i386 # Create fat lib by combining the two versions $DEVROOT/usr/bin/lipo -arch arm lnsout/$LIBNAME_static.arm -arch i386 lnsout/$LIBNAME_static.i386 -create -output lnsout/$LIBNAME_static
相关文章推荐
- cross-compiling for iPhone dev
- Cross-compiling TensorFlow for the Raspberry Pi
- Undefined symbols for architecture i386 error when compiling siphon for iphone simulator
- Cross-compiling Gtk+-3.12.2 with Wayland-1.3.39 backend for ARM
- Cross Compiling Python for Embedded Linux
- Cross-compiling for ARM
- Cross Platform library in C++ for Windows, WM, WinCE, MacOS, iPhone
- Cross Compiling Python for Embedded Linux
- iphone app 开发:HOWTO build the toolchain for Iphone-dev
- Cross compiling Tiny-X (XFree86-4.8) for arm
- Cross-compiling GNU libmicrohttpd for OpenWRT
- Compiling FreeType for iPhone
- Cross-compiling Qt Embedded 5.5 for Raspberry Pi 2
- Cross compiling wxDFB-2.8.11 for ARM-Linux
- Cross Compiling For ARM With Autoconf
- Cross-compiling Apache httpd 2.2.19 for uclibc
- Cross Compiling Python for Embedded Linux
- 下载APP for IPAD, iPhone 设定不同步
- Cross platform debugging proxy for web developers base on NodeJS
- ug二次开发讲座 / Lecture of NX Secondary Dev. for NX OPEN