Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-03-2009, 10:03 AM   #1 (permalink)
New Member
 
Join Date: May 2009
Posts: 2
Default Compile C++ code for iPhone

I'm attempting to get the Tesseract OCR engine to work with the iPhone.
(tesseract-ocr - Google Code)
Currently what I have done is compile the C++ code through the terminal using the makefile provided with the source code. I then copied the unix executable into my Xcode project, and have written an Objective-C wrapper.

This works great in the simulator, but I'm pretty sure it won't work on the device because the tesseract C++ is compiled for the Mac, not for ARM/iPhone.

Searching for a solution I came across this blog post:
Latenitesoft: Mac & iPhone Applications: iPhone Programming Tips: building Unix software

The section explaining "The Problem" sounds identical to my problem, but unfortunately I don't really understand "The Solution" section at all.

So I was wondering if anyone else had tried something like this and got it to work, or if anyone knows of a tutorial or explanation of what to do.
mcs07 is offline   Reply With Quote
Old 05-12-2009, 05:21 PM   #2 (permalink)
New Member
 
Join Date: May 2009
Posts: 1
Default

I am trying to do something very similar to what you are doing. I usually cross compile for ARM on Linux and Unix systems but I am totally unaware of ObjectiveC and iphone SDK.

I'll try to cross compile tesseract OCR over the weekend and provide you the shell commands to get it done for your system.

If possible, can you provide me to the sample xcode project with simple objective-C wrapper to test my compilation?

Last edited by jolly1312; 05-12-2009 at 06:17 PM.
jolly1312 is offline   Reply With Quote
Old 05-12-2009, 08:25 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 188
Default

Neat stuff. Let us know how this goes... interested in dabbling in this too.
jsonli is offline   Reply With Quote
Old 06-24-2009, 02:00 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 2
Default Success?

If you managed to compile it, then I'm interested in the files. I've worked with tesseract before and it's very good if you train it for something specific. I'm currently using it for number recogniction in a project with about 99% accuracy. I would love to use the a port to a similar project to the Iphone.
Thanks, Lars.
larlid is offline   Reply With Quote
Old 07-01-2009, 10:54 PM   #5 (permalink)
zim
Registered Member
 
Join Date: Jun 2009
Posts: 13
Default

What the blog post is suggesting is that you compile the library from the command line (which you have said you can do :-) for both the iPhone (architecture arm-apple-darwin9) and the iPhone Simulator (architecture i386) as a fat static library (that is, a library that gets built into your executable statically at compile time, rather than loaded in dynamically at run time, where the library contains code for both architectures) and add the library and header files to your project.

This avoids the need for you to define the rules necessary to build the libraries from within Xcode.

Code:
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.0.sdk
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 LDFLAGS="-L$SDKROOT/usr/lib/ -Wl,-dylib_install_name,@executable_path/$LIBNAME"
export CXXFLAGS="$CFLAGS"
./configure CXX=/Developer/Platforms/iPhoneOS.platform/Developer/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
cp ccmain/libtesseract_full.a libtesseract_full_armv6.a
make distclean
unset CPPFLAGS CFLAGS CPP LDFLAGS CPP CXXFLAGS
./configure
make
cp ccmain/libtesseract_full.a libtesseract_full_i386.a
$DEVROOT/usr/bin/lipo -arch armv6 libtesseract_full_armv6.a -arch i386 libtesseract_full_i386.a -create -output libtesseract_full.a
Add that libtesseract_full.a file to your Xcode project's Frameworks section, set an include path entry in project settings or add the relevant include files into your project, and you should be set.
zim is offline   Reply With Quote
Old 07-07-2009, 03:06 PM   #6 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 1
Default

Hi,
is there any sample implemetation to test the lib?


BR
init5
init5 is offline   Reply With Quote
Old 07-14-2009, 07:24 PM   #7 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 1
Default

zim, I'm doing what you said but when I execute the last step, I get this error:

command to execute:

$DEVROOT/usr/bin/lipo -arch armv6 libtesseract_full_armv6.a -arch i386 libtesseract_full_i386.a -create -output libtesseract_full.a

and the Error:

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo: specifed architecture type (armv6) for file (libtesseract_full_armv6.a) does not match it's cputype (7) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))

Could you help me, please, because I don't know how to solve this problem
Thanks
fracasado is offline   Reply With Quote
Old 07-29-2009, 03:30 PM   #8 (permalink)
New Member
 
Join Date: May 2009
Posts: 2
Default

This blog post was pretty useful:
exploration Blog Archive cross-compiling for iPhone dev
mcs07 is offline   Reply With Quote
Old 08-21-2009, 04:46 PM   #9 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: France
Age: 31
Posts: 3
Default

Quote:
Originally Posted by mcs07 View Post
You can check my cross compilation tutorial on iphone.olipion.com
I show how to cross-compile library such libssh2, libcurl, zbar barcode reader or tesseract ocr for iphone and simulator.

Regards,
Olipion
olipion is offline   Reply With Quote
Old 09-03-2009, 01:17 PM   #10 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 2
Default

I've managed to compile it now, but I get an linking error when I try to:
static int result = tess->InitWithLanguage(NULL,NULL,NULL,NULL,false,0,NULL );

This works fine though:
TessBaseAPI *tess = new TessBaseAPI();

The error is symbol not found...

Anybody who has managed to use tesseract in any way yet?
Lars.
larlid is offline   Reply With Quote
Old 10-13-2009, 05:01 PM   #11 (permalink)
Senior member
 
Join Date: May 2009
Location: Lille, France
Posts: 34
Default and now

Quote:
Originally Posted by larlid View Post
I've managed to compile it now, but I get an linking error when I try to:
static int result = tess->InitWithLanguage(NULL,NULL,NULL,NULL,false,0,NULL );

This works fine though:
TessBaseAPI *tess = new TessBaseAPI();

The error is symbol not found...

Anybody who has managed to use tesseract in any way yet?
Lars.
Hi,

After reading your posts I was wondering if you made it work or not

cheers

greg
Gregoire is offline   Reply With Quote
Old 11-02-2009, 01:59 AM   #12 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 3
Default HELP

Can you help me with entire xcode proj file as i am stuck with code39 bar code reader for IPhone , if you help me with the xcode project file i will be great
therock is offline   Reply With Quote
Old 11-02-2009, 02:00 AM   #13 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 3
Default Help

would you like to help with xcode project file , that will help a lot
therock is offline   Reply With Quote
Old 12-21-2009, 02:54 AM   #14 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 3
Default How to build Tesseract-OCR for Iphone device.

Hi

I am able to run the tesseract -ocr library in a IPhone simulator and it seems to work nice and fine.

But when I tried to build the code for Iphone device I got the following error:

'libtesseract_full.a, file is not of required architecture'

I am using MAC OSX10.5.8 and Iphone SDK3.1.


It will be very nice if somebody can help me on this issue.
Desperately looking for a solution to this.


Lots of thanks in advance...

Thanks & Regards
Subhasis
subhasis_bose is offline   Reply With Quote
Old 02-21-2010, 07:03 AM   #15 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 1
Default

I can compile Tesseract 2.04 but this script does not work for Tesseract 3.0 svn. Has anyone can success for compiling latest version?
elninom is offline   Reply With Quote
Old 06-04-2010, 08:21 AM   #16 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
Default Phone similar to iPhone(maybe)

Hi I was wondering if this library that works on the iPhone would work on a different phone (Samsung Wave) which has a very similar processor. If not can someone please find a way to do this? I have no idea how and I dont have a Mac or Linux xomputer. Please reply quickly I need help soon>
geniass is offline   Reply With Quote
Old 09-10-2010, 01:24 AM   #17 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 1
Exclamation Cross compiling tesseract - run on iPhone

HI,
I'm using the following script to build the tesseract in my mac OS X 10.6.2. I'm getting the following error, please help me to resolve this.

Regards,
Shane.

=========Script============
#!/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:
# Latenitesoft: Mac & iOS Applications: iPhone Programming Tips: building Unix software
#
# 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/iPhoneOS4.0.sdk
export PATH=$DEVROOT/usr/bin:$PATH

# Set up relevant environment variables
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin10/4.0.1/include/ -I$SDKROOT/usr/include/ -miphoneos-version-min=4.0"
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-darwin10-g++-4.0.1 CC=$DEVROOT/usr/bin/arm-apple-darwin10-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
==========================

===Error i'm Getting============
/usr/bin/lipo: specifed architecture type (arm) for file (lnsout/libtesseract_full.a.arm) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (0))
=======


Cheers,
sam1122 is offline   Reply With Quote
Old 09-22-2010, 02:20 PM   #18 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 9
Default

Quote:
Originally Posted by olipion View Post
You can check my cross compilation tutorial on iphone.olipion.com
I show how to cross-compile library such libssh2, libcurl, zbar barcode reader or tesseract ocr for iphone and simulator.

Regards,
Olipion
any idea on how to implement libssh2 connection, authentication via password and executing command uptime only when a button is pressed (command execudted only when the button is pressed)? Please help!
jaxian is offline   Reply With Quote
Reply

Bookmarks

Tags
c++, makefile, unix, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 296
20 members and 276 guests
ADY, Alsahir, Dani77, e2applets, iph_s, JasonR, keeshux, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, Rudy, sebasx, sly24, Touchmint, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,759
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0