Compiling tesseract v3 for iPhone

Update 2: Before using the script, ensure that you can build tesseract for your host system normally. Also, I only tested the script with the v3 release of tesseract, not svn HEAD. If you get build errors, please try with rev 498.

Update: The script has been updated, thanks mostly to the prompting of fopen2003 in the comments below. I’ve successfully tested the resulting libs in both Simulator and an iPhone 4 (both at iOS4.x) using the PocketOCR project.

After many requests, I finally got around to looking into updating the build script to cross-compile tesseract ocr v3 for use with iPhone. Here’s the script. It seems to build the static, fat library without error. I haven’t tried to update my app to use it yet, so I really don’t know if it even works. Let me know in the comments if it actually does indeed work.

  1. Check out the svn source of tesseract: http://code.google.com/p/tesseract-ocr/source/checkout
  2. Copy this script into the source directory and run from there
  3. Profit???

The libraries will be in a directory named “outdir”

#!/bin/sh
# build_fat.sh
#
# Created by Robert Carlsen on 15.07.2009. Updated 24.9.2010
# build an arm / i386 lib of standard linux project
#
# initially configured for tesseract-ocr v2.0.4
# updated for tesseract prerelease v3

outdir=outdir
mkdir -p $outdir/arm $outdir/i386

libdirs=( api ccutil ccmain ccstruct classify cutil dict image textord training viewer wordrec )
libs=( api ccutil main ccstruct classify cutil dict image textord training viewer wordrec )
count=${#libdirs[@]}


make distclean
unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk
export CFLAGS="-arch armv6 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/"
export CPPFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
export LD="$DEVROOT/usr/bin/ld"
export CPP="$DEVROOT/usr/bin/cpp-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export CC="$DEVROOT/usr/bin/gcc-4.2"
./configure --host=arm-apple-darwin 
make -j3

index=0
while [ "$index" -lt "$count" ]
do
    cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/arm/libtesseract_${libs[index]}_armv6.a
    ((index++))
done


make distclean
unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.1.sdk
export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/"
export CPPFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
export LD="$DEVROOT/usr/bin/ld"
export CPP="$DEVROOT/usr/bin/cpp-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export CC="$DEVROOT/usr/bin/gcc-4.2"
./configure
make -j3

index=0
while [ "$index" -lt "$count" ]
do
    cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/i386/libtesseract_${libs[index]}_i386.a
    ((index++))
done


# are the fat libs making the bundle too big?
index=0
while [ "$index" -lt "$count" ]
do
    /usr/bin/lipo -arch armv6 $outdir/arm/libtesseract_${libs[index]}_armv6.a -arch i386 $outdir/i386/libtesseract_${libs[index]}_i386.a -create -output $outdir/libtesseract_${libs[index]}.a
    ((index++))
done

unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT

Tags: , , , , ,

101 Responses to “Compiling tesseract v3 for iPhone”

  1. exploration » Blog Archive » cross-compiling for iPhone dev Says:

    [...] Update #3: script for use with tesseract v3 posted. [...]

  2. jinahadam Says:

    creates the libraries.
    i included the libraries , added the new baseapi.h
    but when i call “TessBaseAPI *tess;”
    it says TessBaseAPI was not declared in this scope.

  3. shane Says:

    ran the script,copy the libtesseract_api.a & baseapi.h pocket OCR project ,build the project getting errors
    TessBaseAPI was not declared in this scope.
    error: thresholder.h: No such file or directory
    error: ‘ImageThresholder’ has not been declared
    etc..

  4. Robert Says:

    Perhaps there are other headers from tesseract which you need to include in the PocketOCR project.

  5. fopen2003 Says:

    Hi shane, jinahadam,

    try “using namespace tesseract;” in which TessBaseAPI is declared. Also add to your header search path the tesseract directory.

    Hi Robert,

    are you sure your script works? I had errors, needed to make and include libz.a, libtiff.a and all libtesseract_*.a (libtesseract_ccstruct.a etc), to get no compilation errors. is this necessary?

    Is “export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk” correct for simulator? iPhoneSimulator4.1.sdk?

    I changed the script, see below, get no compilation errors, but in simulator i get: “Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
    fopen$UNIX2003 …”

    what is wrong? i see your non-v3 script is much longer…

    Did anyone succeed in having a xcode 3.2.4 iOS4.1 tesseract 3 project working (not only compilation, but also running)?

    Please post the reply here.

    Thanks!

    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT
    make clean
    make distclean
    export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk
    export CPPFLAGS=”-I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/ -miphoneos-version-min=3.0″
    export CFLAGS=”$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT”
    export LDFLAGS=”-L$SDKROOT/usr/lib/”
    export CXXFLAGS=”$CFLAGS”
    export CPP=”$DEVROOT/usr/bin/cpp-4.2 $CPPFLAGS”
    export CXX=”$DEVROOT/usr/bin/g++-4.2 $CXXFLAGS”
    export CC=”$DEVROOT/usr/bin/gcc-4.2 $CFLAGS”
    ./configure LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin
    make -j4
    cp api/.libs/libtesseract_api.a libtesseract_api_armv6.a
    cp ccutil/.libs/libtesseract_ccutil.a libtesseract_ccutil_arm6.a
    cp ccmain/.libs/libtesseract_main.a libtesseract_main_arm6.a
    cp ccstruct/.libs/libtesseract_ccstruct.a libtesseract_ccstruct_arm6.a
    cp classify/.libs/libtesseract_classify.a libtesseract_classify_arm6.a
    cp cutil/.libs/libtesseract_cutil.a libtesseract_cutil_arm6.a
    cp dict/.libs/libtesseract_dict.a libtesseract_dict_arm6.a
    cp image/.libs/libtesseract_image.a libtesseract_image_arm6.a
    cp textord/.libs/libtesseract_textord.a libtesseract_textord_arm6.a
    cp training/.libs/libtesseract_training.a libtesseract_training_arm6.a
    cp viewer/.libs/libtesseract_viewer.a libtesseract_viewer_arm6.a
    cp wordrec/.libs/libtesseract_wordrec.a libtesseract_wordrec_arm6.a

    make distclean
    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT
    export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk
    export CPPFLAGS=”-I$SDKROOT/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/ -miphoneos-version-min=3.0″
    export CFLAGS=”-arch i386 -pipe -no-cpp-precomp”
    export LDFLAGS=”-L$SDKROOT/usr/lib/”
    export CXXFLAGS=”$CFLAGS”
    export CPP=”$DEVROOT/usr/bin/cpp-4.2 $CPPFLAGS”
    export CXX=”$DEVROOT/usr/bin/g++-4.2 $CXXFLAGS”
    export CC=”$DEVROOT/usr/bin/gcc-4.2 $CFLAGS”
    ./configure
    make -j4
    cp api/.libs/libtesseract_api.a libtesseract_api_i386.a
    cp ccutil/.libs/libtesseract_ccutil.a libtesseract_ccutil_i386.a
    cp ccmain/.libs/libtesseract_main.a libtesseract_main_i386.a
    cp ccstruct/.libs/libtesseract_ccstruct.a libtesseract_ccstruct_i386.a
    cp classify/.libs/libtesseract_classify.a libtesseract_classify_i386.a
    cp cutil/.libs/libtesseract_cutil.a libtesseract_cutil_i386.a
    cp dict/.libs/libtesseract_dict.a libtesseract_dict_i386.a
    cp image/.libs/libtesseract_image.a libtesseract_image_i386.a
    cp textord/.libs/libtesseract_textord.a libtesseract_textord_i386.a
    cp training/.libs/libtesseract_training.a libtesseract_training_i386.a
    cp viewer/.libs/libtesseract_viewer.a libtesseract_viewer_i386.a
    cp wordrec/.libs/libtesseract_wordrec.a libtesseract_wordrec_i386.a

  6. fopen2003 Says:

    “compilation errors” i mean while building an xcode project with tesseract v3

  7. fopen2003 Says:

    update: have no longer the fopen error, using a merge of the script here with http://sites.google.com/site/olipion/cross-compilation/tesseract-ocr and

    export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.1.sdk (note the iPhoneSimulator, not iPhoneOS)

    however, how have the following error when running in the simulator:

    dyld: Symbol not found: _Config
    Referenced from: /Users/fopen2003/Project/tesseract/i386/lib/libtesseract_training.3.dylib
    Expected in: dynamic lookup

    anyone has an idea?

    thanks!

  8. fopen2003 Says:

    I removed the dynamic lib files and then get the following warnings, now the code does not build in xcode anymore.

    ld: warning: in /Users/fopen2003/Project/tesseract/i386/lib/libtesseract_api.a, file was built for unsupported file format which is not the architecture being linked (i386)

    however,

    lipo -info libtesseract_api.a
    input file libtesseract_api.a is not a fat file
    Non-fat file: libtesseract_api.a is architecture: i386

    ???

  9. JohnDoe Says:

    Robert, have you tried including the japanese trainedata?

  10. Robert Says:

    No, only english.

  11. Robert Says:

    I omitted the other libs and the configure script detected that I didn’t install them. In PocketOCR I’m sending raw image data to tesseract anyway, so they’re not needed. Ymmv.

    Thanks for the other updates. I had a few moments to tinker, and seem to have a working build of the libs in the PocketOCR Xcode project, but only tried simulator so far.

  12. JohnDoe Says:

    Robert, could you post the final script for ver3. I got all my codes mixed up. :-)

  13. jinahadam Says:

    still getting compilation errors in xcode, anybody got it working?

    thanks.

  14. fopen2003 Says:

    hi robert, i’m also interested in the final script :-) can you give a hint how to send raw data to tesseract ? thx

  15. Robert Says:

    The PocketOCR app is already sending raw pixel data from the captured UIImage object. That’s available on github.

    The script is mostly your additions to my initial version. It seems that I did indeed miss all the supporting libs that the API communicates with. I have only tried on the simulator and will update after it’s working on the device.

  16. fopen2003 Says:

    Great, i will have a look on github.

    I excluded the tiff and zlib again, and added all supporting libs. Now here is the error i get. I assume it is related to the raw sending of the image? Build with xcode fails.

    Undefined symbols:
    “_TIFFReadScanline”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “_TIFFScanlineSize”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “__TIFFmalloc”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “_TIFFGetField”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “__TIFFfree”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    i modified your script as follows:

    export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk
    export CPPFLAGS=”-I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/4.2.1/include/ -I$SDKROOT/usr/include/ -miphoneos-version-min=3.0″
    export CFLAGS=”$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT”
    export LDFLAGS=”-L$SDKROOT/usr/lib/”
    export CXXFLAGS=”$CFLAGS”
    export CPP=”$DEVROOT/usr/bin/cpp-4.2 $CPPFLAGS”
    export CXX=”$DEVROOT/usr/bin/g++-4.2 $CXXFLAGS”
    export CC=”$DEVROOT/usr/bin/gcc-4.2 $CFLAGS”
    ./configure LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin
    make -j4
    cp api/.libs/libtesseract_api.a libtesseract_api_armv6.a
    cp ccutil/.libs/libtesseract_ccutil.a libtesseract_ccutil_armv6.a
    cp ccmain/.libs/libtesseract_main.a libtesseract_main_armv6.a
    cp ccstruct/.libs/libtesseract_ccstruct.a libtesseract_ccstruct_armv6.a
    cp classify/.libs/libtesseract_classify.a libtesseract_classify_armv6.a
    cp cutil/.libs/libtesseract_cutil.a libtesseract_cutil_armv6.a
    cp dict/.libs/libtesseract_dict.a libtesseract_dict_armv6.a
    cp image/.libs/libtesseract_image.a libtesseract_image_armv6.a
    cp textord/.libs/libtesseract_textord.a libtesseract_textord_armv6.a
    cp training/.libs/libtesseract_training.a libtesseract_training_armv6.a
    cp viewer/.libs/libtesseract_viewer.a libtesseract_viewer_armv6.a
    cp wordrec/.libs/libtesseract_wordrec.a libtesseract_wordrec_armv6.a

    make distclean
    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT
    export CFLAGS=”-arch i386 -pipe -no-cpp-precomp”
    export CXXFLAGS=”$CFLAGS”
    ./configure
    make -j4
    cp api/.libs/libtesseract_api.a libtesseract_api_i386.a
    cp ccutil/.libs/libtesseract_ccutil.a libtesseract_ccutil_i386.a
    cp ccmain/.libs/libtesseract_main.a libtesseract_main_i386.a
    cp ccstruct/.libs/libtesseract_ccstruct.a libtesseract_ccstruct_i386.a
    cp classify/.libs/libtesseract_classify.a libtesseract_classify_i386.a
    cp cutil/.libs/libtesseract_cutil.a libtesseract_cutil_i386.a
    cp dict/.libs/libtesseract_dict.a libtesseract_dict_i386.a
    cp image/.libs/libtesseract_image.a libtesseract_image_i386.a
    cp textord/.libs/libtesseract_textord.a libtesseract_textord_i386.a
    cp training/.libs/libtesseract_training.a libtesseract_training_i386.a
    cp viewer/.libs/libtesseract_viewer.a libtesseract_viewer_i386.a
    cp wordrec/.libs/libtesseract_wordrec.a libtesseract_wordrec_i386.a

    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_api_armv6.a -arch i386 libtesseract_api_i386.a -create -output libtesseract_api.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_ccutil_armv6.a -arch i386 libtesseract_ccutil_i386.a -create -output libtesseract_ccutil.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_main_armv6.a -arch i386 libtesseract_main_i386.a -create -output libtesseract_main.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_ccstruct_armv6.a -arch i386 libtesseract_ccstruct_i386.a -create -output libtesseract_ccstruct.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_classify_armv6.a -arch i386 libtesseract_classify_i386.a -create -output libtesseract_classify.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_cutil_armv6.a -arch i386 libtesseract_cutil_i386.a -create -output libtesseract_cutil.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_dict_armv6.a -arch i386 libtesseract_dict_i386.a -create -output libtesseract_dict.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_image_armv6.a -arch i386 libtesseract_image_i386.a -create -output libtesseract_image.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_textord_armv6.a -arch i386 libtesseract_textord_i386.a -create -output libtesseract_textord.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_training_armv6.a -arch i386 libtesseract_training_i386.a -create -output libtesseract_training.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_viewer_armv6.a -arch i386 libtesseract_viewer_i386.a -create -output libtesseract_viewer.a
    $DEVROOT/usr/bin/lipo -arch armv6 libtesseract_wordrec_armv6.a -arch i386 libtesseract_wordrec_i386.a -create -output libtesseract_wordrec.a

    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT

    added all *.a as frameworks to the project, and added the tesseract dir to the header search path recursively in xcode.

    Thanks again.

  17. fopen2003 Says:

    (i mean added all *.a without *_i386.a, *_armv6.a, of course)

  18. jinahadam Says:

    tested the libraries out in ur pocketOCR app, works smoothly.

  19. fopen2003 Says:

    Thanks, Robert.

    Did anyone succeed in having some debug info about the image recognition? The instructions here http://code.google.com/p/tesseract-ocr/wiki/ViewerDebugging did not work. I don’t seem to be able to build the ScrollView.jar. This would be useful to include in the script.

  20. Robert Says:

    I’m not sure exactly what you mean about building this Java debug / test suite. Java doesn’t run on (a vanilla) iOS.

  21. JohnDoe Says:

    it compiled well. but the eng.traineddata seem to be corrupted. Error openning data file

  22. JohnDoe Says:

    or my compilation is corrupted.. hmm… suggestions?

  23. AbhishekSharma Says:

    Thanks for the amazing script! Was able to test PocketOCR on my latest ipod touch smoothly..

  24. Bob M Says:

    Hi Robert,

    I’m having trouble getting the script above to execute cleanly to build the tesseract libraries. I haven’t used Unix for years and am just a novice in that area. I’m guessing that’s where the problem lies. Following the directions you’ve provided I copied the script to the ‘tesseract-ocr-read-only’ folder that gets created after downloading. Then cd’ed there and executed the script which returns the errors output below. It seems nothing gets built at all. Are there environment variables that need to be setup in the terminal prior to running the script. ? As I said please forgive my ignorance in the Unix arena, any help or insight would be greatly appreciated.

    Regards,
    BobM

    apples-mac-pro:tesseract-ocr-read-only apple$ . build_fat.sh
    make: *** No rule to make target `distclean’. Stop.
    configure: WARNING: If you wanted to set the –build type, don’t use –host.
    If a cross compiler is detected then cross compile mode will be used.
    checking build system type… i686-apple-darwin10.4.0
    checking host system type… arm-apple-darwin
    checking –enable-graphics argument… yes
    checking whether the C++ compiler works… no
    configure: error: in `/volumes/terra/ISTOCR/tesseract-ocr-read-only’:
    configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.
    make: *** No targets specified and no makefile found. Stop.
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory
    cp: ccstruct/.libs/libtesseract_ccstruct.a: No such file or directory
    cp: classify/.libs/libtesseract_classify.a: No such file or directory
    cp: cutil/.libs/libtesseract_cutil.a: No such file or directory
    cp: dict/.libs/libtesseract_dict.a: No such file or directory
    cp: image/.libs/libtesseract_image.a: No such file or directory
    cp: textord/.libs/libtesseract_textord.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    cp: viewer/.libs/libtesseract_viewer.a: No such file or directory
    cp: wordrec/.libs/libtesseract_wordrec.a: No such file or directory
    make: *** No rule to make target `distclean’. Stop.
    checking build system type… i686-apple-darwin10.4.0
    checking host system type… i686-apple-darwin10.4.0
    checking –enable-graphics argument… yes
    checking whether the C++ compiler works… yes
    checking for C++ compiler default output file name… a.out
    checking for suffix of executables…
    checking whether we are cross compiling… configure: error: in `/volumes/terra/ISTOCR/tesseract-ocr-read-only’:
    configure: error: cannot run C++ compiled programs.
    If you meant to cross compile, use `–host’.
    See `config.log’ for more details.
    make: *** No targets specified and no makefile found. Stop.
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory
    cp: ccstruct/.libs/libtesseract_ccstruct.a: No such file or directory
    cp: classify/.libs/libtesseract_classify.a: No such file or directory
    cp: cutil/.libs/libtesseract_cutil.a: No such file or directory
    cp: dict/.libs/libtesseract_dict.a: No such file or directory
    cp: image/.libs/libtesseract_image.a: No such file or directory
    cp: textord/.libs/libtesseract_textord.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    cp: viewer/.libs/libtesseract_viewer.a: No such file or directory
    cp: wordrec/.libs/libtesseract_wordrec.a: No such file or directory
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_api_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_ccutil_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_main_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_ccstruct_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_classify_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_cutil_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_dict_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_image_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_textord_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_training_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_viewer_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_wordrec_armv6.a (No such file or directory)

  25. Bob M Says:

    duh. never mind about that last message. I didn’t realize I needed to change the iPhone versions to 4.0 as I have not installed 4.1 yet.

  26. Robert Says:

    Cool…glad it was an easy fix.

  27. Dafer Says:

    Hello,

    Thanks for the shell script, it runs great!

    But I still have XCode complaining about libtiff(I suppose) at linking:
    “_TIFFReadScanline”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “_TIFFScanlineSize”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “_TIFFGetField”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “__TIFFmalloc”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    “__TIFFfree”, referenced from:
    read_tiff_image(tiff*, IMAGE*) in libtesseract_main.a(tessedit.o)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Any idea on this error?

    Regards

  28. Robert Says:

    What does your configure output mention regarding libtiff? Do you have libtiff installed already on your system?
    You could try to force tesseract to ignore libtiff by passing “–with-libtiff=nil” to the configure script.

  29. Dafer Says:

    You were right, Robert, I have libtiff installed through MacPorts.

    But “-with-libtiff=nil” did the trick: I have Pocket OCR running smoothly on the simulator. Yay!
    Maybe the build script should be modified to add the “-with-libtiff=niff” argument, so people with libtiff installed can avoid my previous error.

    Anyway, thanks for the help, appreciate it!

  30. Iain Says:

    I’m a mac (and tesseract) newbie trying work out what to do with this :(

    I’m not sure which directory it should be in. I’ve downloaded the tessarct v3.00 source and out this script in the root (which contains makefile.am, tessdata, api and other directories).

    I can run it and it creates the output directory, but that’s the last thing that works.
    here’s a snippet of the output

    make: *** No rule to make target `distclean’. Stop.
    configure: WARNING: If you wanted to set the –build type, don’t use –host.
    If a cross compiler is detected then cross compile mode will be used.
    checking build system type… i686-apple-darwin10.4.1
    checking host system type… arm-apple-darwin
    checking –enable-graphics argument… yes
    ./configure: line 2888: test: /Users/iain/Documents/tesseract: binary operator expected
    ./configure: line 2891: test: /Users/iain/Documents/tesseract: binary operator expected
    checking whether the C++ compiler works… no
    configure: error: in `/Users/iain/Documents/tesseract 3.00/tesseract-3.00′:
    configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.
    make: *** No targets specified and no makefile found. Stop.
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory

    I’m sure I’m doing something really simple wrong! Any help much appreciated.

    Iain

  31. Robert Says:

    Try:
    -removing spaces in your path (folder names).
    -make sure you edit the script to reflect the version of the iPhone sdk you have installed (4.0, 4.1, etc.)

  32. Iain Says:

    Thanks, that worked fine. Now all I have to do is get it working with the OCR sample! ;)

  33. JohnDoe Says:

    update tesseract 3 http://code.google.com/p/tesseract-ocr/downloads/list FYI

  34. JohnDoe Says:

    what if i want to translate japanese, chinese, english all together. How can I do that?

  35. Robert Says:

    That’s a great question. I don’t know. Maybe the tesseract documentation would have some insight. Let us know what you find. Good luck!

  36. johndoe Says:

    I was thinking threading

  37. tgate Says:

    How do you actually import the libraries into a iphone project? The PocketOCR seems to gives error when importing the baseapi.h

  38. tgate Says:

    actually i ended up getting it to work. it was a issue with having the old libraries still around. but my issue now is how to set variables now, i used to use TessBaseAPI::SetVariable(“variablename”,”value”), but now it doesn’t seem to like that. Anyone know the syntax for setting variables now?

  39. mbogh Says:

    Hey Robert,

    When running the script i get the following error:

    libtool: link: unsupported hardcode properties
    libtool: link: See the libtool documentation for more information.
    libtool: link: Fatal configuration error.
    make[3]: *** [libtesseract_main.la] Error 1
    make[2]: *** [all-recursive] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_api_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_main_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_training_armv6.a (No such file or directory)

    checkout’ed tesseract to: /Users/morten/Documents/awesomeOCR/tesseract-ocr-read-only/ and saved the script to /Users/morten/Documents/awesomeOCR/tesseract-ocr-read-only/nice.sh

    I have 4.1 SDK installed.

  40. nprof50 Says:

    I’m getting the same problem as the above mentioned.

  41. MarLoe Says:

    Hi Robert!

    Nice script! It works smoothly and everything compiles and links!!!
    Well until last week. I started getting linking errors.
    I figured out that you need to update your script for ARM7 as well.

  42. pravin Says:

    hi,
    Thanks for the code and script, that was the good point to start with, while trying to run the project I am getting following error –
    ” “tesseract::TessBaseAPI::Init(char const*, char const*, char**, int, bool)”, referenced from: -[OCRDisplayViewController viewDidLoad] in OCRDisplayViewController.o ” and also at
    ” “tesseract::TessBaseAPI::TessBaseAPI()”, referenced from: -[OCRDisplayViewController viewDidLoad] in OCRDisplayViewController.o ”

    u know why this could be ?
    Thanks for your help.

  43. pravin Says:

    I got it working, I did not build the script properly after reinstalling the tesseract. I am not able to read the digits on the image, its returning some special characters..do I have to include any special files for digits…

    Thanks…

  44. petnic Says:

    Unfortunately, I have been unable to get the script to generate libtesseract_api_armv6.a. The last 20 lines read as follows,

    Making all in api
    make[2]: Entering directory `/afs/umich.edu/user/c/a/caugusty/Desktop/tesseract-ocr-read-only/api’
    make[2]: *** No rule to make target `all’. Stop.
    make[2]: Leaving directory `/afs/umich.edu/user/c/a/caugusty/Desktop/tesseract-ocr-read-only/api’
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/afs/umich.edu/user/c/a/caugusty/Desktop/tesseract-ocr-read-only’
    make: *** [all] Error 2
    cp: cannot stat `api/.libs/libtesseract_api.a’: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory
    build_fat.sh: line 67: /usr/bin/lipo: No such file or directory

    Has anyone encountered this error before? Has anyone found a solution?

    Thanks.

  45. Robert Says:

    That error message doesn’t tell us much except the lib wasn’t created. The script has no sanity checking so it told lipo to create fatlibs for files which aren’t there.

    Can you build the library normally with configure and make?

  46. Christophe Says:

    Hi Robert,

    I’va a little problem, I can test your application on simulator and it’work well,
    but when I try to build for device I get build failed, with 4 compilation errors :

    - “TessBaseAPI::TesseractRect(unsigned char const*, int, int, int, int, int, int)”, referenced from:
    - “TessBaseAPI::SimpleInit(char const*, char const*, bool)”, referenced from:
    etc

    Do you have an idea of why it’s doing that?

  47. Christophe Says:

    And I get this warning too

    ld: warning: in libtesseract_full.a, file was built for unsupported file format which is not the architecture being linked (armv6)

  48. Wojciech Radomski Says:

    Hi,
    i am newbie in developing aps on MAC, i don’t know also much about linux.
    I am trying to build tesseract based on your instructions. I have errors when I am trying to run this line:

    xxx$ ./configure –host=arm-apple-darwin
    configure: WARNING: If you wanted to set the –build type, don’t use –host.
    If a cross compiler is detected then cross compile mode will be used.
    checking build system type… i686-apple-darwin10.5.0
    checking host system type… arm-apple-darwin
    checking –enable-graphics argument… yes
    checking whether the C++ compiler works… no
    configure: error: in `/Users/wojciechradomski/Documents/iTraff/OCR/PocketOCR/tesseract-3.00′:
    configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.

    There are hundreds of lines in config.log by my linux knowledge is to pure to say anything abut this

    i am running this by: bash build_fat.sh

    of course I also tried to run whole script, thousands of lines on console but at the end i am having:

    Making all in vs2008
    Making all in dlltest
    make[3]: Nothing to be done for `all’.
    Making all in include
    Making all in leptonica
    make[4]: Nothing to be done for `all’.
    make[4]: Nothing to be done for `all-am’.
    make[3]: Nothing to be done for `all-am’.
    make[2]: Nothing to be done for `all-am’.
    ./build_fat.sh: line 32:  : command not found
    ./build_fat.sh: line 37: syntax error near unexpected token `(‘
    ./build_fat.sh: line 37: `    ((index++))’

    And nothing in the folder outdir

    Any ideas what I am doing wrong?

  49. Robert Says:

    Do you have the Developer Tools and the iPhone SDK installed? (line 32 is the “make” command and is included in the tools)
    Have you edited build_fat.sh to reflect the version of the SDK you have installed?

  50. Wojciech Radomski Says:

    I installed newest xCode and Application Tools as well.
    I changed the path in build_fat.sh to:
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.2.sdk
    export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.2.sdk

    i run sudo ./build_fat.sh
    and still getting errors: (configuration is now done properly)


    Configuration is done.
    You can now build tesseract by running:

    % make
    make all-recursive
    Making all in ccstruct



    Making all in vs2008
    Making all in dlltest
    make[3]: Nothing to be done for `all’.
    Making all in include
    Making all in leptonica
    make[4]: Nothing to be done for `all’.
    make[4]: Nothing to be done for `all-am’.
    make[3]: Nothing to be done for `all-am’.
    make[2]: Nothing to be done for `all-am’.
    ./build_fat.sh: line 24: syntax error near unexpected token `(‘
    ./build_fat.sh: line 24: `    ((index++))’

  51. Wojciech Radomski Says:

    i got it working, don’t really know what was wrong. Installing new xCode probably helped

  52. Christophe Says:

    May you compile the librairie and upload it please.

  53. Todd Says:

    I’m also having problems with the build script. Can anyone
    give me an idea of what is wrong? . . . libtool: compile:
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2
    -DHAVE_CONFIG_H -I. -I.. -I../ccutil -I../cutil -I../image
    -I../viewer -arch i386 -pipe -no-cpp-precomp
    -isysroot/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk
    -miphoneos-version-min=3.0
    -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include/
    -I/opt/local/include -arch i386 -pipe -no-cpp-precomp
    -isysroot/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk
    -miphoneos-version-min=3.0
    -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include/
    -MT ccstruct.lo -MD -MP -MF .deps/ccstruct.Tpo -c ccstruct.cpp -o
    ccstruct.o >/dev/null 2>&1 coutln.cpp: In
    member function ‘void C_OUTLINE::render(int, int, Pix*)’:
    coutln.cpp:632: error: ‘PIX_DST’ was not declared in this scope
    coutln.cpp:632: error: ‘PIX_NOT’ was not declared in this scope
    coutln.cpp:632: error: ‘pixRasterop’ was not declared in this scope
    coutln.cpp:635: error: ‘PIX_DST’ was not declared in this scope
    coutln.cpp:635: error: ‘PIX_NOT’ was not declared in this scope
    coutln.cpp:635: error: ‘pixRasterop’ was not declared in this scope
    make[3]: *** [coutln.lo] Error 1 make[3]: *** Waiting for
    unfinished jobs…. mv -f .deps/ccstruct.Tpo .deps/ccstruct.Plo mv
    -f .deps/boxword.Tpo .deps/boxword.Plo make[2]: *** [all-recursive]
    Error 1 make[1]: *** [all-recursive] Error 1 make: *** [all] Error
    2 cp: api/.libs/libtesseract_api.a: No such file or directory cp:
    ccutil/.libs/libtesseract_ccutil.a: No such file or directory cp:
    ccmain/.libs/libtesseract_main.a: No such file or directory . .
    .

  54. Todd Says:

    Figured it out. Don’t checkout lastest Tesseract SVN.
    Download the 3.00 release instead. Recent dependency changes break
    the build. I’m not getting great results from the OCR
    though.

  55. GammaPoint Says:

    For 3.00 release try this cmd for checkout: svn checkout -r
    r498 http://tesseract-ocr.googlecode.com/svn/trunk/
    tesseract-ocr3.00

  56. HenrySW Says:

    Robert thx for the script =], I got the library working for both simulator and device

    For anyone having problem with setting up the path with the library in XCode try this:

    This is base on the given PocketOCR example,

    1.) In Xcode goto “–> Project –> Edit Project Settings”
    2.) Under “Base SDK for All configurations:” set it to the lastest SDK version that you are using

    3.) In XCode goto “–> Project –> Edit Active Target OCR”
    4.) A menu will appear, click on the “Build” tab
    5.) Highlight “Header Search Paths”. and then at the bottom right of the menu click on the “gear wheel icon” and click “Add Build Setting Condition”, do this twice on the “Header Search path”
    6.) For the condition under “Header Search Paths”, set “Any iOS , Any Architecture” and the other one with “Any iOS simulator , Any Architecture”
    7.) For both condition under the “Header Search Paths”, add the following path “$(SRCROOT)/../../directory name of the tesseract file” and tick the “Recursive box”
    8.) Now under your “Header search Paths” should look like this:
    [Header Search Paths]
    – [Any iOS | Any Architecture | "$(SRCROOT)/../../ directory name of the tesseract file "]
    – [Any iOS simulator | Any Architecture | "$(SRCROOT)/../../directory name of the tesseract file "]

    9.) Just for the sake of it, do the same for the ” Library Search Paths” with the two setting condition
    10.) Now under your “Library Search Paths” should look like this:
    [Library Search Paths]
    – [Any iOS | Any Architecture | $(inherited) ]
    “$(SRCROOT)” ]
    “$(SRCROOT)/../../directory name of the tesseract file” ]
    “$(SRCROOT)/../../directory name of the tesseract file outdir ” ]

    – [Any iOS simulator | Any Architecture | $(inherited) ]
    “$(SRCROOT)” ]
    “$(SRCROOT)/../../directory name of the tesseract file” ]
    “$(SRCROOT)/../../directory name of the tesseract file/outdir” ]

    11.) In the menu, make sure your have the “Base SDK” set to the lastest version that you are using.
    12.) Now try build and compile for both simulator and devices.
    Hope this helps =]”

  57. GammPoint Says:

    I had to delete the vs2008 folder and remove it from the
    top level Makefile & configure shell scripts. Otherwise it
    was not compiling. I got some errors on the last step where lipo
    was used to combine the arm6 & i386 libraries into a single
    .a lib file: “should be cputype (7) and cpusubtype (3)”. So I am
    unable to use in simulator. But by deleting the links from the
    XCode (Frameworks), and adding the *arm6.a lib files under
    framework I am able to run the program on the iPhone4 with 4.2
    firmware. Thanks OP. I also did the changes suggested by HenrySW
    above.

  58. Junior Says:

    Hi Robert,

    I’m having a problem compiling the script for 4.2. Here are my steps (please forgive me, I’m a newbie).

    1. svn checkout -r r498 http://tesseract-ocr.googlecode.com/svn/trunk/ tesseract-ocr3.00
    2. Copy this script into the source directory of tesseract-ocr3.00
    3. Update export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk to export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.2.sdk
    4. run it from there
    5 here’s what i get:

    make: *** No rule to make target `distclean’. Stop.
    /Users/jrman52/Desktop/OCR/tesseract-ocr3.00/build_fat.sh: line 30: ./configure: No such file or directory
    make: *** No targets specified and no makefile found. Stop.
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory
    cp: ccstruct/.libs/libtesseract_ccstruct.a: No such file or directory
    cp: classify/.libs/libtesseract_classify.a: No such file or directory
    cp: cutil/.libs/libtesseract_cutil.a: No such file or directory
    cp: dict/.libs/libtesseract_dict.a: No such file or directory
    cp: image/.libs/libtesseract_image.a: No such file or directory
    cp: textord/.libs/libtesseract_textord.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    cp: viewer/.libs/libtesseract_viewer.a: No such file or directory
    cp: wordrec/.libs/libtesseract_wordrec.a: No such file or directory
    make: *** No rule to make target `distclean’. Stop.
    /Users/jrman52/Desktop/OCR/tesseract-ocr3.00/build_fat.sh: line 53: ./configure: No such file or directory
    make: *** No targets specified and no makefile found. Stop.
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory
    cp: ccstruct/.libs/libtesseract_ccstruct.a: No such file or directory
    cp: classify/.libs/libtesseract_classify.a: No such file or directory
    cp: cutil/.libs/libtesseract_cutil.a: No such file or directory
    cp: dict/.libs/libtesseract_dict.a: No such file or directory
    cp: image/.libs/libtesseract_image.a: No such file or directory
    cp: textord/.libs/libtesseract_textord.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    cp: viewer/.libs/libtesseract_viewer.a: No such file or directory
    cp: wordrec/.libs/libtesseract_wordrec.a: No such file or directory
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_api_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_ccutil_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_main_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_ccstruct_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_classify_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_cutil_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_dict_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_image_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_textord_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_training_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_viewer_armv6.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_wordrec_armv6.a (No such file or directory)

    As I mentioned, I’m new to all this, so help would be appreciated =)

  59. Robert Says:

    The beginning of the console output mentioned that the configure script isn’t found. Is it in the same dir as the build script?

    When checking out that svn revision of tesseract do you need autotools to generate the configure script?

    I’ve only used the released v2.04 source which was ready to build.

  60. Soeren Says:

    My findings:

    Using the above svn checkout my build also failed with something similar to above – but using the download tesseract-3.00.tar.gz all compiled and linked. Do ask me what the differences is :-)

    Now I just have to try the libs in the OCR app

  61. hkloo Says:

    Hi, i tested , but when i compile in xCode for 4.2 it keep showing me the error

    Baseapi.h : No such file or directory
    tesseract is not a namespace-name

    Did i missing something?

  62. Tudor Munteanu Says:

    For iOS 4.2 change
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.1.sdk
    with
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.2.sdk

    Hope this helps

  63. Chris Says:

    How do you change the script to handle iOS 4.3 and tesseract-3.00.tar.gz (Sep 30, 2010)? It seems like armv6 is no longer available on iOS 4.3 so I just changed everything that says armv6 to armv7.

    However, there are other errors … it seems like the configure went ok but the error now is on the i386




    libtool: link: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libtesseract_ccstruct.3.dylib .libs/blobbox.o .libs/blobs.o .libs/blread.o .libs/callcpp.o .libs/ccstruct.o .libs/coutln.o .libs/detlinefit.o .libs/genblob.o .libs/labls.o .libs/linlsq.o .libs/lmedsq.o .libs/mod128.o .libs/normalis.o .libs/ocrblock.o .libs/ocrrow.o .libs/otsuthr.o .libs/pageres.o .libs/pdblock.o .libs/points.o .libs/polyaprx.o .libs/polyblk.o .libs/polyblob.o .libs/polyvert.o .libs/poutline.o .libs/quadlsq.o .libs/quadratc.o .libs/quspline.o .libs/ratngs.o .libs/rect.o .libs/rejctmap.o .libs/statistc.o .libs/stepblob.o .libs/vecfuncs.o .libs/werd.o -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/ -lpthread -ljpeg -lz -arch i386 -miphoneos-version-min=3.0 -install_name /usr/local/lib/libtesseract_ccstruct.3.dylib -compatibility_version 4 -current_version 4.0 -Wl,-single_module
    ld: file not found: /usr/lib/system/libdispatch_sim.dylib for architecture i386
    collect2: ld returned 1 exit status
    make[3]: *** [libtesseract_ccstruct.la] Error 1
    make[2]: *** [all-recursive] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory
    cp: ccstruct/.libs/libtesseract_ccstruct.a: No such file or directory
    cp: classify/.libs/libtesseract_classify.a: No such file or directory
    cp: cutil/.libs/libtesseract_cutil.a: No such file or directory
    cp: dict/.libs/libtesseract_dict.a: No such file or directory
    cp: image/.libs/libtesseract_image.a: No such file or directory
    cp: textord/.libs/libtesseract_textord.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    cp: viewer/.libs/libtesseract_viewer.a: No such file or directory
    cp: wordrec/.libs/libtesseract_wordrec.a: No such file or directory
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_api_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_ccutil_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_main_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_ccstruct_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_classify_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_cutil_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_dict_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_image_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_textord_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_training_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_viewer_armv7.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/arm/libtesseract_wordrec_armv7.a (No such file or directory)

  64. iamqk Says:

    -isysroot$SDKROOT should be -isysroot $SDKROOT
    add space in the para to make it work
    enjoy it!

  65. johndoe Says:

    robert, under GPL, I can modify, edit and sell the compiled application right?

  66. Robert Says:

    “John”, the GPL does not limit your freedom to use, modify or redistribute a GPL-licensed program…provided that you also extend the same freedoms. You can distribute the source and binary, for free or for a fee.

    You should refer to the GNU site for further clarity:
    http://www.gnu.org/licenses/gpl-faq.html

    If you were to simply package up my demo PocketOCR iOS app and sell it, I don’t think there is a legal block in doing so. It’s not a terribly good idea since the code was written quickly as a proof of concept and is likely not fit for production. I, or anyone else (with an Apple Developer account) could also distribute the binary as well, gratis, which would certainly undercut sales of the same app. You could modify the app, adding features and functionality, or translations into other languages, and sell that of course, but you’d have to make the source of your modifications available under the GPL as well, which anyone else would necessarily be free to redistribute themselves.

    TesseractOCR is released under the Apache license which is considered a more permissive license that GPL.

    Hope that’s helpful.

  67. johndoe Says:

    what if I don’t want to share the source code I modified? Or I only got a part of it?

  68. Robert Says:

    Thanks for the note.

    I revisited the build script this evening to get it working with SDK4.3…I’ll update the example this weekend.

  69. Robert Says:

    You should familiarize yourself with the GPL. The link I provided earlier is a good start.

    One incentive behind free software licenses is that you can get a lot of functionality which other people have created – helping you to get your modifications or project going faster. Requiring you to extend the same terms on your contributions allows other people to benefit from your work in the same way that you have from others’ work.

    You are under no obligation whatsoever to use GPL’d code in your work. You are certainly welcome to write everything yourself (or pay for a different license, or commission a programmer to write it for you, etc.), and demand whatever terms you’d like. That said, you don’t have to release your modified source code if you are not distributing your work publicly.

    Again, the Tesseract OCR code is under a completely different license than the GPL. I’m unsure if you’re referring here to a specific “compiled application” or an application in an abstract sense.

    (also, use a different e-mail address – i certainly know that you’re not an admin of *my* site)

  70. jl Says:

    Thank you so much for the updated script! It worked perfectly! I’ve been agonizing over this for the past couple days. Your update was perfect timing.

  71. RobM Says:

    Hi Robert, I have been trying to compile tesseract v3 for the 4.3 SDK and have run into a funny error. Maybe you can help me out. I believe the compile goes well until the simulator, that is where I think there is an issue.

    libtool: link: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 -arch i386 -pipe -no-cpp-precomp -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -miphoneos-version-min=3.0 -I /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/include/ -o .libs/unicharset_extractor unicharset_extractor.o -Wl,-bind_at_load -L/Developer/Platforms/iPhoneSimulator.ƒplatform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/ ../ccutil/.libs/libtesseract_ccutil.dylib -lpthread -lz
    ld: warning: duplicate dylib /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib//system/libSystem.host.dylib
    Undefined symbols:
    “__Unwind_Resume”, referenced from:
    _main in unicharset_extractor.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make[3]: *** [unicharset_extractor] Error 1
    make[2]: *** [all-recursive] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: training/.libs/libtesseract_training.a: No such file or directory
    /usr/bin/lipo: can’t open input file: outdir/i386/libtesseract_api_i386.a (No such file or directory)
    /usr/bin/lipo: can’t open input file: outdir/i386/libtesseract_training_i386.a (No such file or directory)

  72. Tobias Says:

    i am experiencing the same problem. did you figure out how to make it work?

  73. zinuk Says:

    Thank you Robert for your great tutorial.I have build your script successfully for iOS 4.1 and also device 3G.But,when i used(again i h’ve build for 4.3) it for sdk 4.3 it worked for simulator but failed for device 4G …and error like this

    Error openning data file /Users/abc/Desktop/MyOCR/tessdata/eng.traineddata

    so,what is wrong here ???

    i initialized tesseract engine like this way…..
    /****************************************************************************/
    NSString *dataPath = @”/Users/abc/Desktop/MyOCR/tessdata”;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:dataPath]) {
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];

    NSString *tessdataPath = @”/Users/abc/Desktop/MyOCR/tessdata-svn”;
    if (tessdataPath) {
    [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
    }
    }

    setenv(“TESSDATA_PREFIX”, [@"/Users/abc/Desktop/MyOCR//" UTF8String], 1);

    tess = new TessBaseAPI();
    tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding],”eng”);
    /*********************************************************************************************/

  74. zinuk Says:

    sorry again,this is my final code

    NSString *dataPath = @”/Users/abc/Desktop/MyOCR/tessdata”;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:dataPath]) {
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];

    NSString *tessdataPath = @”/Users/abc/Desktop/MyOCR/tessdata-svn”;
    if (tessdataPath) {
    [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
    }
    }

    setenv(“TESSDATA_PREFIX”, [@"/Users/abc/Desktop/MyOCR/" UTF8String], 1);

    tess = new TessBaseAPI();
    tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding],”eng”);

  75. Justin Says:

    Hi,

    I am a newbie here, so please tolerate my ignorance. I am trying to install tesseract for mac and iphone and I’m running into troubles. In fact, I can’t even install it for mac os x alone even without Robert’s script. I am trying to install tesseract for mac os x, and I have run into trouble trying to “make” it. There seems to be some issues with the cpu type…

    Btw, before installing Tesseract, in addition to Leptonica, do I need other packages?

    Here are the following steps I took:

    1. install Leptonica 1.68 by running
    ./configure
    make
    sudo make install

    2. download tesseract 3.0 (revision 581)

    3. attempting to install:
    ./runautoconf
    ./configure
    make

    But I run into issue with “make”.

    First, I get warnings:

    ld: warning: ignoring file .libs/blobbox.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/blobs.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/blread.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/boxword.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/ccstruct.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/detlinefit.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/dppoint.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/genblob.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/linlsq.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/matrix.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/mod128.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/normalis.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/ocrblock.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/otsuthr.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/pageres.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/points.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/polyaprx.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/publictypes.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/quadlsq.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/quadratc.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/ratngs.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/rejctmap.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/seam.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/split.o, file was built for armv7 which is not the architecture being linked (x86_64)
    ld: warning: ignoring file .libs/vecfuncs.o, file was built for armv7 which is not the architecture being linked (x86_64)

    Then I get errors about my cpu type:

    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(callcpp.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(coutln.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(ocrrow.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(pdblock.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(polyblk.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(quspline.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(rect.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(statistc.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(stepblob.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    /usr/bin/ranlib: archive member: .libs/libtesseract_ccstruct.a(werd.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    libtool: link: ranlib .libs/libtesseract_ccstruct.a
    ranlib: archive member: .libs/libtesseract_ccstruct.a(callcpp.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(coutln.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(ocrrow.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(pdblock.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(polyblk.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(quspline.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(rect.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(statistc.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(stepblob.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    ranlib: archive member: .libs/libtesseract_ccstruct.a(werd.o) cputype (16777223) does not match previous archive members cputype (12) (all members must match)
    make[3]: *** [libtesseract_ccstruct.la] Error 1
    make[2]: *** [all-recursive] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2

    I know it’s possible to install on Mac OS X, and it seems that others have figured out a way, but I am stuck on this for days and I’d be really thankful if someone could land a hand!

  76. Tobias Says:

    Hi everybody,

    I finally managed to compile the libs for iphone sdk 4.3. Everything works and I am getting decent results.

    what i am worried about is the size of the libraries. is the a way to strip down the libs to get smaller libs?

    thanks for your help

  77. Robert Says:

    Yeah, after all that work in making a fat lib, it’s probably better to make separate iPhone / Simulator libs and conditionally link them based on the target platform. I’ve set up a project to do this for the Omniture libs…it’s not difficult.

    The iPhone lib would still have to be armv6 / armv7, though.

  78. Oleg Says:

    Hi Tobias,
    how did you fix the error:

    Undefined symbols:
    “__Unwind_Resume”, referenced from:
    _main in unicharset_extractor.o
    ld: symbol(s) not found

    thx

  79. Tobias Says:

    the script states

    export CFLAGS=”-arch i386 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/”

    even for the i386.

    i changed this to -mmacosx-version-min=10.6.0, seemed to do the trick – but actually i am not quite sure if that was it.

    also i compiled the i386 against SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.2.sdk

  80. Oleg Says:

    Hello Tobias,
    with -mmacosx-version-min=10.6.0 for i386 everything compiled fine.
    thx

  81. arya Says:

    Hi, I am a newbie here. i tried tesseract 3.0 for mac and i phone by using your script here and modifying /iPhoneOS4.1.sdk into /iPhoneOS4.3.sdk
    and this is the error i got, i hope that u can help me. thanks in advance

    checking whether the C++ compiler works… no
    configure: error: in `/Users/khim/Documents/BelajarIOS/library/tesseract-3.00′:
    configure: error: C++ compiler cannot create executables
    See `config.log’ for more details.
    make: *** No targets specified and no makefile found. Stop.
    cp: api/.libs/libtesseract_api.a: No such file or directory
    cp: ccutil/.libs/libtesseract_ccutil.a: No such file or directory
    cp: ccmain/.libs/libtesseract_main.a: No such file or directory

  82. Robert Says:

    Do you have the Developer Tools installed? Can you compile Tesseract by itself, without using the script?

  83. Kyle Bailey Says:

    Robert thank you for this great library.

    I am definetly a newbie.

    Which library files do I attach (arm/i386) How do I attach these library files (*.a) to my xcode sample project.

    This is awesome

  84. Robert Says:

    If you are using the provided script (and it completed successfully) there should be several .a files in “outdir”. (I’ve used r585)

    Here is the list of libraries I’ve included:
    libtesseract_api.a, libtesseract_ccutil.a, libtesseract_cutil.a, libtesseract_image.a, libtesseract_textord.a, libtesseract_viewer.a, libtesseract_ccstruct.a, libtesseract_classify.a, libtesseract_dict.a, libtesseract_main.a, libtesseract_training.a, libtesseract_wordrec.a

    Drag all the .a files into the Frameworks group in the PocketOCR Xcode project. You may also have to add those .a files to the “Link Binary with Libraries” build phase of the OCR target.

    You’ll probably have to update the User Header Search Paths to wherever you have located the tesseract ocr source.

  85. stan Says:

    Hi Robert,

    I have tried to compile r585 using the script but have fail. mainly can’t copy library.

    Here’s are some of the environment.
    XCode 3.2.5
    iPhoneOS4.2/iPhoneSimulator4.2

    Is there any dependency that I need to install?

    Thanks!

  86. Robert Says:

    What is the output from the build script? Can you build successfully normally (ie. without the script)?

  87. ryen Says:

    can we keep the shell script at https://gist.github.com/ to track changes ? Thanks.

  88. Robert Says:

    That’s a good idea…I’ll see what I can do about that.

  89. Robert Says:

    Created a gist with the shell script:
    https://gist.github.com/1029171

  90. ryen Says:

    I have iPhoneOS4.3 sdk, and building tesseract 3.0 works for i386, but not arm. I have error here (below), any ideas ? It’s like it doesn’t recognize my arm v6 configuration??

    stepblob.o .libs/vecfuncs.o .libs/werd.o -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/ -lpthread -lz -arch armv6 -miphoneos-version-min=3.0 -install_name /usr/local/lib/libtesseract_ccstruct.3.dylib -compatibility_version 4 -current_version 4.0 -Wl,-single_module
    ld: file not found: /usr/lib/system/libcache.dylib for architecture armv6
    collect2: ld returned 1 exit status
    make[3]: *** [libtesseract_ccstruct.la] Error 1

  91. ryen Says:

    nevermind my last post, I guess with iPhoneOS4.3 , things have changed with arm versions. It seems iPhoneOS4.3 can only build against armv7, not sure.

  92. Robert Says:

    Why is it trying to link against a system lib?

  93. ryen Says:

    I do not know why it is linking against a system lib :O Seems like something is messed up in my build environment, unfortunately I am new to debugging make/build errors.
    I don’t think it should be a problem, but I did remove XCode3.2 before installing XCode 4.0 Final release. Anything else I should be looking at ?

  94. Sergio Says:

    Hi,

    I’m triying to use 3.00 library in iPhone project (for iOS 4.3/armv7 and later)
    It compiles good but when try to run project it returns and errors:

    http://imageshack.us/photo/my-images/703/screenshot20110802at527.png
    http://imageshack.us/photo/my-images/718/screenshot20110802at528.png

    Seems that there is no declaration read_and_textord() function in whole codebase (version 3.00).
    But previously it was decelerated in version 2.04 in file “tordmain.h”

    Could you please tell me how to fix it?

    Thank you in advance.

  95. Ed Says:

    Hi,

    Please bear with me I’m a n00b. On the Pocket OCR demo app, can I run it on the iPhone simulator and use static images instead of the camera? If so, how do I get those images I want to use available in the simulator?

    Thanks!

  96. Aris Kox Says:

    if you get this message
    ld: file not found: /usr/lib/system/libcache.dylib for architecture armv6

    change both LDFLAGS lines to
    export LDFLAGS=”-L$SDKROOT/usr/lib/ -L$SDKROOT/usr/lib/system”

    You could use the following script to build for armv6,armv7 & i386 and compile everything to a fat binary

    Check this http://pastebin.com/UeJx2jYf

  97. springday Says:

    hello Robert, thank your script.i have builded the projet.but when i recognize photo,the speed was very slow. so i want to use Binary Images.
    uint8_t *m_imageData = (uint8_t *) malloc(m_width * m_height);
    for(int y = 0; y < m_height; y++) {
    for(int x = 0; x >24)&255; count++;}
    if (colors & kGreen) {sum += (rgbPixel>>16)&255; count++;}
    if (colors & kBlue) {sum += (rgbPixel>>8)&255; count++;}
    m_imageData[y*m_width+x]=sum/count;
    if(m_imageData[y*m_width+x]>125)
    {
    m_imageData[y*m_width+x]=1;
    }
    else
    m_imageData[y*m_width+x]=0;

    }
    }
    can i use
    char* text = tess->TesseractRect(imageData,
    bytes_per_pixel,
    bytes_per_line,
    0, 0,
    imageSize.width, imageSize.height);

  98. Arthur Says:

    Thanks for this great post.

    I have got a failure when running build_fat.sh, the scrips fails when on configuration at the line 30. It complains on leptonica: configure: error: leptonica library missing.
    But there is’t any problem to build the tessaract on my Mac!?!

    I used tessaract revision 640. My MacOSX version is 10.6.7 and iPhone SDK4.3 (I fixed the SDK version in the script).

    May be Im doing a simple mistake, but please help.

  99. Ricky Says:

    I have the same issue with Arthur….error: leptonica library missing, when I tried to compile with build_fat.sh

    But I can successfully build tesseract with ./configure make

    I’m using mac os lion, xcode 4.3 ios5.0 sdk. anybody have the updated script for this configuration? It frustrates me for few days….really appreciate if somebody can help

  100. Ricky Says:

    Here’s my script:
    ———————————-
    outdir=outdir
    mkdir -p $outdir/armv6 $outdir/armv7 $outdir/i386

    libdirs=( api ccutil ccmain ccstruct classify cutil dict image textord training viewer wordrec )
    libs=( api ccutil main ccstruct classify cutil dict image textord training viewer wordrec )
    count=${#libdirs[@]}

    ### ARM V6
    make distclean
    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

    export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS5.0.sdk
    export CFLAGS=”-arch armv6 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/”
    export CPPFLAGS=”$CFLAGS”
    export CXXFLAGS=”$CFLAGS”
    export LDFLAGS=”-L$SDKROOT/usr/lib/ -L$SDKROOT/usr/lib/system”
    export LD=”$DEVROOT/usr/bin/ld”
    export CPP=”$DEVROOT/usr/bin/llvm-cpp-4.2″
    export CXX=”$DEVROOT/usr/bin/llvm-g++-4.2″
    export CC=”$DEVROOT/usr/bin/llvm-gcc-4.2″
    ./configure –host=arm-apple-darwin
    make -j3

    index=0
    while [ "$index" -lt "$count" ]
    do
    cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/armv6/libtesseract_${libs[index]}_armv6.a
    ((index++))
    done

    libdirs=( api ccutil ccmain ccstruct classify cutil dict image textord training viewer wordrec )
    libs=( api ccutil main ccstruct classify cutil dict image textord training viewer wordrec )
    count=${#libdirs[@]}

    ### ARM V7
    make distclean
    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

    export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneOS5.0.sdk
    export CFLAGS=”-arch armv7 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/”
    export CPPFLAGS=”$CFLAGS”
    export CXXFLAGS=”$CFLAGS”
    export LDFLAGS=”-L$SDKROOT/usr/lib/ -L$SDKROOT/usr/lib/system”
    export LD=”$DEVROOT/usr/bin/ld”
    export CPP=”$DEVROOT/usr/bin/llvm-cpp-4.2″
    export CXX=”$DEVROOT/usr/bin/llvm-g++-4.2″
    export CC=”$DEVROOT/usr/bin/llvm-gcc-4.2″
    ./configure –host=arm-apple-darwin
    make -j3

    index=0
    while [ "$index" -lt "$count" ]
    do
    cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/armv7/libtesseract_${libs[index]}_armv7.a
    ((index++))
    done

    make distclean
    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

    export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
    export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator5.0.sdk
    export CFLAGS=”-arch i386 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/”
    export CPPFLAGS=”$CFLAGS”
    export CXXFLAGS=”$CFLAGS”
    export LDFLAGS=”-L$SDKROOT/usr/lib/ -L$SDKROOT/usr/lib/system”
    export LD=”$DEVROOT/usr/bin/ld”
    export CPP=”$DEVROOT/usr/bin/llvm-cpp-4.2″
    export CXX=”$DEVROOT/usr/bin/llvm-g++-4.2″
    export CC=”$DEVROOT/usr/bin/llvm-gcc-4.2″
    ./configure
    make -j3

    index=0
    while [ "$index" -lt "$count" ]
    do
    cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/i386/libtesseract_${libs[index]}_i386.a
    ((index++))
    done

    # are the fat libs making the bundle too big?
    index=0
    while [ "$index" -lt "$count" ]
    do
    /usr/bin/lipo -arch armv6 $outdir/armv6/libtesseract_${libs[index]}_armv6.a -arch armv7 $outdir/armv7/libtesseract_${libs[index]}_armv7.a -arch i386 $outdir/i386/libtesseract_${libs[index]}_i386.a -create -output $outdir/libtesseract_${libs[index]}.a
    ((index++))
    done

    unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT

  101. Duncan Says:

    Here is a solution for iOS5 and SDK 4.x. For OCR tesseract 3.01 and leptonica 1.68.

    http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/

Leave a Reply