Hi ShreeDevi

Thanks for your advice anyway, it got me thinking about the problem in 
other ways. I'm pleased to say that I managed to get a build script that 
works using the following versions of the libs:

LIBJPEG_VERSION=9b
ZLIB_VERSION=1.2.11
LIBPNG_VERSION=1.6.29
LEPTONICA_VERSION=1.71
TESSERACT_VERSION=3.04.01

I couldn't get it to work with any later versions of Leptonica (1.74.1 is 
the latest) or Tesseract (3.05.00 is the latest v3).  Despite this, I now 
have a working standalone Mac version of Tesseract that I can drive from my 
own code!

Apart from the actual files themselves, it's necessary to set 2 environment 
variables:

TESSDATA_PREFIX - set to the parent folder for the tessdata folder
DYLD_LIBRARY_PATH - set to the path up to and including the lib folder

I've included my version of the build script in case anyone else needs to 
do something similar.

Thanks again

Peter

On Tuesday, April 18, 2017 at 1:03:22 PM UTC+1, shree wrote:
>
> I haven't built 3.05 so cannot help. I would suggest that you try with 
> older commits of tesseract 3.05 branch to see which one works.
>
> Hope that those who have built 3.05 on mac will help.
>

-- 
You received this message because you are subscribed to the Google Groups 
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tesseract-ocr+unsubscr...@googlegroups.com.
To post to this group, send email to tesseract-ocr@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tesseract-ocr/9fb3ad6f-ecd2-47e7-8afb-dd9e34396af0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/bin/bash

#
# Build Script for making standalone version of Tesseract
# Wes Fowlks
# 10/01/2014
# Originally posted at:https://code.google.com/p/tesseract-ocr/issues/detail?id=1326
# Original pastebin source: http://pastebin.com/VnGLHfbr

# NOTE:
# Peter Reid, 20 April 2017
# you must set 2 environment variables to locate the runnable version of Tesseract:
#   TESSDATA_PREFIX - set to the parent folder for the tessdata folder
#   DYLD_LIBRARY_PATH - set to the path up to and including the lib folder
#
# the runnable version of Tesseract consists of the folder "tesseract" with the following content (comments in brackets):
#
#      bin (folder)
#            tesseract (the executable itself)
#      include (folder)
#            ...
#      lib (folder - pointed to by DYLD_LIBRARY_PATH)
#            ...
#      share (folder - pointed to by TESSDATA_PREFIX)
#            man (folder)
#            tessdata (folder)

BUILD_LIBJPEG=1
BUILD_ZLIB=1
BUILD_LIBPNG=1
BUILD_LEPTONICA=1
BUILD_TESSERACT=1

# Get the base directory of where the script is
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_DIR=$BASE_DIR/build
ARCHIVE_DIR=$BASE_DIR/archives
SRC_DIR=$BASE_DIR/src
TESSERACT_DIR=$BASE_DIR/tesseract

#Library Versions - unused newer versions (as of 20 April 2017):
# numerous combinations of versions have been tried but it was necessary to backtrack to earlier versions to avoid build errors
#LEPTONICA_VERSION=1.71 -> 1.74.1
#TESSERACT_VERSION=3.04.01 -> 3.05.00

LIBJPEG_VERSION=9b
ZLIB_VERSION=1.2.11
LIBPNG_VERSION=1.6.29
LEPTONICA_VERSION=1.71
TESSERACT_VERSION=3.04.01

echo
echo
echo "==> STARTING BUILD..."
echo 


echo "==> Base Build Directory: " $BUILD_DIR

# Functions usefull throughtout the script
function setupDirs() {
        if [ ! -d "$ARCHIVE_DIR" ]; then
                mkdir $ARCHIVE_DIR
        fi

        if [ ! -d "$SRC_DIR" ]; then
                mkdir $SRC_DIR
        fi

        if [ ! -d "$BUILD_DIR" ]; then
                mkdir $BUILD_DIR
        fi
}

# FIRST - Build lib Libjpeg
if [[ $BUILD_LIBJPEG = 1 ]]
then
        echo
        echo "==> Building Lib Jpeg"
        setupDirs

        # Clean up old files
        rm -rf $SRC_DIR/jpeg* $BUILD_DIR/jpeg*

        if [ ! -f "$ARCHIVE_DIR/jpegsrc.v$LIBJPEG_VERSION.tar.gz" ]; then
                #Download the file
                curl -o $ARCHIVE_DIR/jpeg.v$LIBJPEG_VERSION.tar.gz http://www.ijg.org/files/jpegsrc.v$LIBJPEG_VERSION.tar.gz
        fi

        echo "==> Extracting archive"
        tar -xzf $ARCHIVE_DIR/jpeg.v$LIBJPEG_VERSION.tar.gz -C $SRC_DIR

        cd "$SRC_DIR/jpeg-$LIBJPEG_VERSION"

        echo "==> Configuring Lib Jpeg for Standalone"
        ./configure --disable-shared --prefix=$BUILD_DIR

        echo "==> Building LIBJPEG and deploying to $BUILD_DIR"
        make install

        #Check if the build was successful
        if [ -f "$BUILD_DIR/include/jpeglib.h" ]; then 
                echo "==> LIB JPEG Build Successful"
        else
                echo "==> LIBJPEG build failed. Exiting."
                exit 1
        fi

else
        echo "==> Skipping LIBJPEG"
fi


# SECOND - Build lib zlib 
if [[ $BUILD_ZLIB = 1 ]]
then
        echo
        echo "==> Building ZLIB"
        setupDirs

        # Clean up old files
        rm -rf $SRC_DIR/zlib* $BUILD_DIR/zlib*

        if [ ! -f "$ARCHIVE_DIR/zlib-$ZLIB_VERSION.tar.gz" ]; then
                #Download the file
                curl -o $ARCHIVE_DIR/zlib-$ZLIB_VERSION.tar.gz http://zlib.net/fossils/zlib-$ZLIB_VERSION.tar.gz
  fi

        echo "==> Extracting archive"
        tar -xzf $ARCHIVE_DIR/zlib-$ZLIB_VERSION.tar.gz -C $SRC_DIR

        cd "$SRC_DIR/zlib-$ZLIB_VERSION"

        echo "==> Configuring ZLIB for Standalone"
        ./configure --solo --static

        echo "==> Building Zlib and deploying to $BUILD_DIR"
        make install prefix=$BUILD_DIR

        #Check if the build was successful
        if [ -f "$BUILD_DIR/include/zlib.h" ]; then 
                echo "==> ZLIB Build Successful"
        else
                echo "==> ZLIB build failed. Exiting."
                exit 1
        fi

else
        echo "==> Skipping ZLib"
fi

# THIRD - Build Lib PNG
if [[ $BUILD_LIBPNG = 1 ]]
then
      echo
        echo "==> Building Lib PNG"
        setupDirs

        # Clean up old files
        rm -rf $SRC_DIR/libpng* $BUILD_DIR/libpng*

        if [ ! -f "$ARCHIVE_DIR/libpng-$LIBPNG_VERSION.tar.gz" ]; then
                #Download the file
              curl -L -o $ARCHIVE_DIR/libpng-$LIBPNG_VERSION.tar.gz ftp://ftp.simplesystems.org/pub/png/src/history/libpng16/libpng-$LIBPNG_VERSION.tar.gz
        fi

        echo "==> Extracting archive"
        tar -xzf $ARCHIVE_DIR/libpng-$LIBPNG_VERSION.tar.gz -C $SRC_DIR

        cd $SRC_DIR/libpng*

        echo "==> Copying libz header files to libpng"
        cp $BUILD_DIR/include/zlib.h .
        cp $BUILD_DIR/include/zconf.h .

        echo "==> Configuring Lib PNG for Standalone"
        ./configure --prefix=$BUILD_DIR

        echo "==> Building LIBPNG and deploying to $BUILD_DIR"
        make check
        make install

        #Check if the build was successful
        if [ -f "$BUILD_DIR/include/libpng16/png.h" ]; then 
                echo "==> LIB PNG Build Successful"
        else
                echo "==> LIBPNG build failed. Exiting."
                exit 1
        fi

else
        echo "==> Skipping LIBPNG"
fi

# FOURTH - Build Leptonica
if [[ $BUILD_LEPTONICA = 1 ]]
then
        echo
        echo "==> Building Leptonica"
        setupDirs

        # Clean up old files
        rm -rf $SRC_DIR/leptonica* $BUILD_DIR/leptonica*

        if [ ! -f "$ARCHIVE_DIR/leptonica-$LEPTONICA_VERSION.tar.gz" ]; then
                #Download the file
                curl -o $ARCHIVE_DIR/leptonica-$LEPTONICA_VERSION.tar.gz http://www.leptonica.com/source/leptonica-$LEPTONICA_VERSION.tar.gz
        fi

        echo "==> Extracting archive"
        tar -xzf $ARCHIVE_DIR/leptonica-$LEPTONICA_VERSION.tar.gz -C $SRC_DIR

        cd "$SRC_DIR/leptonica-$LEPTONICA_VERSION"
        
        echo "==> Configuring leptonica for standalone"
        ./make-for-local

        echo "==> Modifying environ.h"
        cat src/environ.h |sed -e 's/#define  HAVE_LIBTIFF     1/#define  HAVE_LIBTIFF     0/g' > src/environ.test.h
        mv src/environ.test.h src/environ.h

        echo "==> Copying dependencies to leptonica"
        cp -r $BUILD_DIR/include src
        cd src

        echo "==> Building LEPTONICA and deploying to $BUILD_DIR"
        make EXTRAINCLUDES="-I./include -I./include/libpng16"

        #Check if the build was successful
        if [ -f "$SRC_DIR/leptonica-$LEPTONICA_VERSION/lib/nodebug/liblept.a" ]; then 
                echo "==> Leptonica Build Successful"
        else
                echo "==> LEPTONICA build failed. Exiting."
                exit 1
        fi

        echo "Copying files for Tesseract"
        cp $SRC_DIR/leptonica-$LEPTONICA_VERSION/lib/nodebug/liblept.a $BUILD_DIR/lib

        if [ ! -f "$BUILD_DIR/include/leptonica" ]; then
                mkdir $BUILD_DIR/include/leptonica
        fi

        cp $SRC_DIR/leptonica-$LEPTONICA_VERSION/src/*.h $BUILD_DIR/include/leptonica

else
        echo "==> Skipping Leptonica"
fi

# FINALLY - Build Tesseract
if [[ $BUILD_TESSERACT = 1 ]]
then
        echo
        echo "==> Building Tesseract..."
        setupDirs
        rm -rf $SRC_DIR/tesseract*

        #Create Tesseract Build Directory
        if [ ! -d "$TESSERACT_DIR" ]; then
                mkdir $TESSERACT_DIR
        else
                rm -rf $TESSERACT_DIR/*
        fi

        if [ ! -f "$ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.tar.gz" ]; then
                #Download the file
               curl -L -o $ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.tar.gz https://github.com/tesseract-ocr/tesseract/archive/$TESSERACT_VERSION.tar.gz
       fi
 
       echo "==> Extracting archive"
       tar -xzf $ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.tar.gz -C $SRC_DIR
      
        cd "$SRC_DIR/tesseract-$TESSERACT_VERSION"

        cp -r $BUILD_DIR/include src
        cp -r $BUILD_DIR/bin src
        cp -r $BUILD_DIR/lib src
        
        echo "==> Configuring Tesseract..."
        ./autogen.sh
     
        export CXXFLAGS="-I$BUILD_DIR/include -I$BUILD_DIR/include/libpng16 -I$BUILD_DIR/include/leptonica -lpng -ljpeg -lz"
        export CPPFLAGS="-I$BUILD_DIR/include -I$BUILD_DIR/include/libpng16 -I$BUILD_DIR/include/leptonica -lpng -ljpeg -lz"
        export LDFLAGS="-L$BUILD_DIR/lib"
        export LIBLEPT_HEADERSDIR="$BUILD_DIR/include/leptonica"
        
        ./configure --prefix="$TESSERACT_DIR" --with-extra-libraries="$BUILD_DIR/lib"

        echo "==> ...Configuration done"
        echo

        echo "==> start Building Tesseract..."
        make install

        ls $TESSERACT_DIR/bin

        if [ -x "$TESSERACT_DIR/bin/tesseract" ]; then
                echo "Tesseract Build Successful"
        else
                echo "Tesseract build failed. Exiting."
                exit 1
        fi

        echo "==> Checking the language files"
        if [ ! -f "$ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.eng.tar.gz" ]; then
                #Download the file
                curl -L -o $ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.eng.tar.gz https://sourceforge.net/projects/tesseract-ocr-alt/files/tesseract-ocr-$TESSERACT_VERSION.eng.tar.gz
        fi

        echo "==> Checking OSD (Optical Script Detection) models"
        if [ ! -f "$ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.osd.tar.gz" ]; then
                #Download the file
                curl -L -o $ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.osd.tar.gz https://sourceforge.net/projects/tesseract-ocr-alt/files/tesseract-ocr-$TESSERACT_VERSION.osd.tar.gz
        fi

        echo "==> Installing Languages and OSD"
        tar -xzf $ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.eng.tar.gz -C $TESSERACT_DIR/bin
        tar -xzf $ARCHIVE_DIR/tesseract-$TESSERACT_VERSION.osd.tar.gz -C $TESSERACT_DIR/bin

        cd $TESSERACT_DIR/bin

        echo "==> Tesseract is now built and can be found at: $TESSERACT_DIR"

else
        echo
        echo "==> Skipping Tesseract"
fi

Reply via email to