Compile tesseract for iOS SDK 6.0

Update 10/25/12

Added instructions to integrate an armv7s slice in liblept.a and libtesseract_all.a.

Update 09/24/12

To make the iOS integration easier, I made a Github repo containing an Objective-C wrapper for Tesseract. It relies on an other repo containing tesseract & leptonica libs. Feel free to improve them !

More informations about these repos on my next article.

Introduction

I had troubles while following the compiling guide from this blog: http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/. Some dependencies are missing on a fresh Mountain Lion with Xcode 4.5, and more importantly: the build_dependencies.sh won’t work.

Here is why: Xcode 4.5 and iOS SDK 6.0 don’t support armv6 anymore.

So here are the steps to build tesseract-ocr for iOS SDK 6.0.

Requirements

If you don’t have HomeBrew already, that’s a shame. Run to this website and install it.

Then, install libtool and automake:

1
$ brew install libtool automake

You should have installed ‘Command Line Tools’ after the Homebrew installation, but if you forgot: Open Xcode’s preferences, and install them from the ‘Downloads’ tab.

The build process will need libtoolize. Just make a symlink to glibtoolize:

1
$ ln -s /usr/local/bin/glibtoolize /usr/local/bin/libtoolize

We’re good to go.

Sources and compilation

The steps will more or less follow the tinsuke’s article, except for one thing: the build script.

Get the following sources:

Then, organize your folder with the following structure:

1
2
3
4
5
./build/
  dependencies/
  leptonica-1.69/
  tesseract-3.01/
  build_dependencies.sh

You might want to modify build_dependencies.sh to make LEPTON_LIB and TESSERACT_LIB match the proper folders.

Now, you can build the libraries:

1
2
$ chmod +x ./build_dependencies.sh
$ ./build_dependencies

In dependencies/lib/, you’ll find liblept.a and libtesseract_all.a, these are the only libraries you need so you can remove other ones. Both contain armv7 and i386 slices only, but many iOS 5 projects require an armv7s slice.

Just follow this Matt Galloway’s blog post to generate and put an armv7s slice into the libs.

Now you just have to copy dependencies/ in your Xcode Project, and follow my next article on how to use tesseract.

Loïs Di Qual: I'm an iOS developer based in Bordeaux, France. This is my blog.

  • Sly

    Thanks a lot buddy you helped me get it working :)

  • tonjac

    Doesn’t work. Tried with xCode 4.5 and installed command tools. Got the following error:
    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.configure: error: cannot find sources (src/adaptmap.c) in . or ..

    • disqus_tNOfnbKsvP

      Please verify $DEVROOT

  • tonjac

    Solved my issue with error: cannot find sources (src/adaptmap.c) in . or ..
    My bad, corrupt tar.

    But next problem is how to build for armv7s?

    • Aalok Parikh

      Hi @tonjac:disqus I face same problem with this script.
      After some modification I am able to build it for ios6 for armv7s but not for real device.
      Have you found out any solution for it ?

      • ldiqual

        @d96d5962168d57c45165fd1334dc3f46:disqus, could you please add your modification to this gist: https://gist.github.com/3763217 ?
        What’s the error when you build for your device ?

        • erf

          I also get that error when deploying for a real device:

          ld: file is universal (3 slices) but does not contain a(n) armv7s slice: …/build_dependencies/dependencies/lib/liblept.a for architecture armv7s
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

          • erf

            i have an iPhone 3gs with ios sdk 6

        • ldiqual

          @e899c777767722e3e84a6d09ed2172c5:disqus Try to remove armv7s in your target architectures. My script doesn’t include an armv7s version in the tesseract lib. It could be fixed, but I don’t have much time for this :S

  • Karwan

    Thanks a lot. It worked great! I wish there were full set of instructions for compiling a simple App with tesseract.

  • Aris

    Build scripts fails on OS X 10.7.4. XCode CLI tools are installed, libtool and automake installed from Macports, but no binary for libtoolize or glibtoolize is in /usr/local/bin. No output errors, but while liblept.a is created, libtesseract_all is not. Thanks for posting the compiled libs on Github, but any idea how to build this myself?

    • ldiqual

      Did you correctly run `brew install libtool automake` ? What does `brew info libtool` and `which glibtoolize` give you ?

      • Aris

        `which glibtoolize` is /opt/local/bin/glibtoolize because I installed it using Macports. I did ln -s /opt/local/bin/glibtoolize to /usr/local/bin/libtoolize AND /opt/local/bin/libtoolize just in case. The build script doesn’t refer to these directories, it should work if the programs are found on the $PATH, right?

        • ldiqual

          Well, it should. What does `echo $PATH` output ?

  • tonyng

    Hi I am using xcode 4.5 and iphone5. I followed your instruction and still get the error after following your advice:
    file is universal (2 slices) but does not contain a(n) armv7s slice:
    /Users/tonyng/Downloads/cocr/cocr/build/dependencies/lib/liblept.a
    for architecture armv7s

    Then I downloaded the two files from your github: liblept.a, libleptessaract_all.a I still get the error but now complains about other file.
    file is universal (2 slices) but does not contain a(n) armv7s slice: /Users/tonyng/Downloads/cocr/cocr/build/dependencies/lib/libtesseract.a for architecture armv7s

    Can you give me some pointers>

    • http://lois.di-qual.net/ Loïs Di Qual

      I added instructions about how to add an armv7s in liblept.a and libtesseract_all.a. But the problem shouldn’t happen with libs from the Github repo as they both contain an armv7s slice. Could you follow my next article‘s instructions and tell me if it works properly ?

    • ldiqual

      I added instructions about how to add an armv7s in liblept.a and libtesseract_all.a. But the problem shouldn’t happen with libs from the Github repo as they both contain an armv7s slice. Could you follow my next article‘s instructions and tell me if it works properly ? http://lois.di-qual.net/blog/install-and-use-tesseract-on-ios-with-tesseract-ios/

  • http://www.facebook.com/profile.php?id=538545927 Michael Russell

    THanks for posting the compiled libraries.
    I’ve been trying to compile tesseract 3.0.2 using these methods – but just cant get it working.
    THink you could update your github page with updated libraries ?

  • Alessandro Blasi

    Thanks very much for your guide!

  • http://twitter.com/theprojectabot Benji Brown

    Is it possible to build these with libc++?

  • Bhumesh

    Thanks for this post.
    I have one question. I want to scan image continuously and pass to tessearct until I not get my result. How to achieve this functionality?

  • Atp

    I followed the above step but couldn’t create .a files. I got following error message. I don’t know, where did I go wrong.

    ===========
    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… i386-apple-darwin12.0.0

    checking host system type… arm-apple-darwin6

    checking for arm-apple-darwin6-gcc… /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc

    checking whether the C compiler works… no

    configure: error: in `/Users/atp/Downloads/Tesseract/1/build/leptonica-1.69′:

    configure: error: C compiler cannot create executables

    See `config.log’ for more details.

  • Bhumesh

    Why Tesseract is taking too much time to give result. How to speed up tesseract performance? Any suggestion much appreciated.

  • Sumit

    I am using Xcode 7.1.I set otherlinker flag & C++ standard library then also i am getting error as ” unknown argument: ‘-stdc++”