cross-compiling for iPhone dev
来源:互联网 发布:金山毒霸如何备份软件 编辑:程序博客网 时间:2024/05/13 18:56
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:
#!/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 SDKexport DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developerexport SDKROOT=$DEVROOT/SDKs/iPhoneOS3.0.sdk # Set up relevant environment variablesexport 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 packageLIBPATH=$LIBFILE.dylibLIBNAME=`basename $LIBPATH` export LDFLAGS="-L$SDKROOT/usr/lib/ -Wl,-dylib_install_name,@executable_path/$LIBNAME" # Static library that will be generated for ARMLIBPATH_static=$LIBFILE.aLIBNAME_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 locationmkdir -p lnsoutcp $LIBPATH_static lnsout/$LIBNAME_static.arm # Do it all again for native cpumake distclean # Restore default environment variablesunset CPPFLAGS CFLAGS CPP LDFLAGS CXXFLAGS DEVROOT SDKROOT export DEVROOT=/Developerexport 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 nameexport LDFLAGS="-Wl,-dylib_install_name,@executable_path/$LIBNAME" # TODO: error checking./configuremake -j4 # Copy the native library to the temporary locationcp $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
#!/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 SDKexport DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developerexport SDKROOT=$DEVROOT/SDKs/iPhoneOS2.2.sdk # Set up relevant environment variablesexport 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 packageLIBPATH=$LIBFILE.dylibLIBNAME=`basename $LIBPATH` export LDFLAGS="-L$SDKROOT/usr/lib/ -Wl,-dylib_install_name,@executable_path/$LIBNAME" # Static library that will be generated for ARMLIBPATH_static=$LIBFILE.aLIBNAME_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 locationmkdir -p lnsoutcp $LIBPATH_static lnsout/$LIBNAME_static.arm # Do it all again for native cpumake distclean # Restore default environment variablesunset CPPFLAGS CFLAGS CPP LDFLAGS CXXFLAGS # Overwrite LDFLAGS# Dynamic linking, relative to executable_path# Use otool -D to check the install nameexport LDFLAGS="-Wl,-dylib_install_name,@executable_path/$LIBNAME" # TODO: error checking./configuremake -j4 # Copy the native library to the temporary locationcp $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 for iPhone dev
- Cross-compiling for ARM
- Cross compiling Libx264 for ARM
- Compiling FreeType for iPhone
- Cross-Compiling Qt for Embedded Linux Applications
- Cross Compiling Python for Embedded Linux
- Cross Compiling Python for Embedded Linux
- Cross Compiling For ARM With Autoconf
- Cross Compiling Python for Embedded Linux
- Cross-compiling GNU libmicrohttpd for OpenWRT
- Cross-compiling TensorFlow for the Raspberry Pi
- cross compiling in Linux for android(arm_linux) platform
- Cross-compiling Apache httpd 2.2.19 for uclibc
- Cross compiling wxDFB-2.8.11 for ARM-Linux
- How To: Cross compiling libraries for iOS (armv6/armv7/i386)
- Cross-Compiling Iceadtea(OpenJDK)
- Cross-Compiling Under Linux
- SSH中 struts hibernate spring 各起什么作用
- 回到CSDN
- zoj 1001
- sprintf()出错
- zoj 1037
- cross-compiling for iPhone dev
- javascript日期操作方法
- jQuery Ajax 实例 全解析
- zoj 1048
- .NET Framework版本与CLR版本之间的关系
- 六、数组(基本概念)
- abstract factory模式
- zoj 1049
- dma_performance_demo 结构