Menu

Compilation

Anonymous Igor

General Linux

OSRA CLI

  • Compile and/or install all the necessary [Dependencies].
  • Unpack OSRA package.
  • Run ./configure. By default all dependencies should be autodetected. If not, you need to specify them e.g.:
    :
    ./configure --with-tclap-include=/usr/local/include/tclap --with-openbabel-include=/usr/local/include/openbabel3 --with-openbabel-lib=/usr/local/lib

    : Note: In order to generate and install manpages, you need to '''--enable-docs'''
  • Run make all install. Now you can use OSRA from command-line.

Library support

It is possible to compile OSRA as library (.so).

  • All [[dependencies|prerequisites]] that are planned to be statically linked, should be compiled with position-independent code enabled ('''-fPIC''') (not relevant for Windows platform). In particular:
    For OCRAD: configure; make CXXFLAGS="-fPIC"
    For GOCR: configure CFLAGS="-fPIC"; make libs
  • Run ./configure (add any necessary configuration options):
    *:
    ./configure --enable-lib
  • Run make all install. Now both CLI and library are installed.

Java support

  • Download and unpack http://www.oracle.com/technetwork/java/javase/downloads/index.html Sun JDK.
  • Make sure that all [Dependencies] that are planned to be statically linked, are compiled with '''-fPIC''' (see previous chapter).
  • Set the JAVA_HOME variable to point to JDK:
    *:
    export JAVA_HOME=/usr/local/jdk1.6.0_27
  • Run ./configure (add any necessary configuration options):
    *:
    ./configure --enable-java
  • Run make all install. This will install dictionaries in shared folder and library to libs.
  • Run mvn install. This will compile Java part of JNI bridge (in target/osra-1.3.6.jar). Alternatively you can use OsraLib.java that does not depend on JNATI library.
  • Use the source in OsraLibTest.java as example of library usage.

Notes: * JVM looks up the libraries in system-wide directories but also in specified by java.library.path system property. So when starting the java application, make sure this property is properly setup or OSRA library is in system path (/usr/local/lib is usually '''not'''):
:

java -Djava.library.path=/usr/local/lib -cp commons-io-1.4.jar net.sf.osra.OsraLibTest
* Under unknown circumstances OpenBabel is not correctly initialized when dynamically loaded by JNI bridge. The symptom is that for any image the JNI version returns empty chemical strcuture while CLI vresion works OK. The solution in this case is the following:
:
LD_PRELOAD=/usr/local/lib/libopenbabel.so java ...
* It is nearly not possible to compile library (or java library) statically in Linux. This is because most dependencies (POTRACE / OpenBabel / GraphicsMagick) provide libraries for static linking (.a) without position-independent code enabled ('''-fPIC'''). If you wish to include them statically, you need to recompile them the same way as GOCR / OCRAD above (not relevant for Windows platform where all code is position-independent thus creating a statically linked library is easier).

SuSE

OSRA CLI

  • You need SLES v11 or SuSE 11.3.
  • Install the following packages:
    *:
    yast -i \
      gcc-c++ libstdc++-devel \
      libGraphicsMagick++2 libGraphicsMagick2 libGraphicsMagick++-devel \
      libopenbabel3 libopenbabel-devel libnetpbm-devel libbz2-devel
  • The following packages are needed for '''--enable-docs''':
    *:
    yast -i libxslt docbook-xsl-stylesheets
  • Download and build tclap (build prerequisites: yast -i doxygen graphviz libtool fdupes):
    *:
    # wget -nv 'http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_Factory/src/tclap-1.2.0-6.18.src.rpm'
    # rpm -i tclap-1.2.0-6.18.src.rpm
    # rpmbuild -ba /usr/src/packages/SPEC/tclap.spec
    # rpm -i /usr/src/packages/RPMS/i686/tclap-1.2.0-6.18.i686.rpm
  • Download and build potrace (apply the https://sourceforge.net/projects/osra/files/contrib/1.3.6/potrace_1.8.suse.patch.gz/download potrace_1.8.suse.patch.gz or use https://sourceforge.net/projects/osra/files/contrib/1.3.6/potrace-1.8-84.2.src.rpm/download potrace-1.8-84.2.src.rpm):
    *:
    # wget -nv 'http://download.opensuse.org/source/distribution/11.2/repo/oss/suse/src/potrace-1.8-84.1.src.rpm'
    # rpm -i potrace-1.8-84.1.src.rpm
    # zcat potrace_1.8.suse.patch.gz | patch -d /usr/src/packages -p1
    # rpmbuild -ba /usr/src/packages/SPECS/potrace.spec
    # rpm -i /usr/src/packages/RPMS/i686/{potrace-lib-1.8-84.2.i686.rpm,potrace-devel-1.8-84.2.i686.rpm}
  • Download and build ocrad:
    *:
    # wget -nv 'https://sourceforge.net/projects/osra/files/contrib/1.3.7/ocrad-0.20-1.0.src.rpm/download'
    # rpmbuild --rebuild ocrad-0.20-1.0.src.rpm
    # rpm -i /usr/src/packages/RPMS/i686/ocrad-devel-0.20-1.0.i686.rpm
  • Download and build gocr
    *:
    # wget -nv 'https://sourceforge.net/projects/osra/files/contrib/1.3.7/gocr-0.50-1.0.src.rpm/download'
    # rpmbuild --rebuild gocr-0.50-1.0.src.rpm
    # rpm -i /usr/src/packages/RPMS/i686/gocr-devel-0.50-1.0.i686.rpm
  • Optionally you can download, compile and install Cuneiform and Tesseract (you can use '''--with-cuneiform --with-tesseract''' then):
    *:
    # wget -nv 'ftp://rpmfind.net/linux/fedora/development/rawhide/source/SRPMS/cuneiform-1.1.0-4.fc17.src.rpm'
    # rpmbuild --rebuild cuneiform-1.1.0-4.fc17.src.rpm
    # rpm -i /usr/src/packages/RPMS/i686/cuneiform{-devel,}-1.1.0-4.i686.rpm
    # wget -nv 'ftp://rpmfind.net/linux/fedora/development/rawhide/source/SRPMS/tesseract-3.00-2.fc15.src.rpm'
    # rpmbuild --rebuild tesseract-3.00-2.fc15.src.rpm
    # rpm -i /usr/src/packages/RPMS/i686/tesseract{-devel,}-3.00-2.i686.rpm
  • Unpack OSRA package and run
    *:
    ./configure && make all install

Mac OS X

To have static libraries install through MacPorts the following:
libxml2, libiconv, zlib, bzip2, freetype, libpng, tiff, lcms, jasper.

Download and compile JPEG. Macports version does not work.

Compile OCRAD and TCLAP as follows:
:./configure;make;sudo make install

Potrace:
:./configure --with-libpotrace --disable-shared; make; sudo make install

GOCR:
:./configure; make libs; sudo make install

OpenBabel:
:export LDFLAGS=/usr/local/lib/libiconv.a
:mkdir build
:cd build
:cmake -DBUILD_SHARED=OFF ..
:sudo make install

GraphicsMagick:
:./configure --disable-shared --with-x=no --disable-openmp --without-threads
:make
:sudo make install

OSRA (assuming you installed static GraphicsMagick libraries and header files in /Users/igor/build):
:./configure --enable-static-linking --disable-graphicsmagick-config --with-graphicsmagick-lib=/Users/igor/build/lib --with-graphicsmagick-include=/Users/igor/build/include/GraphicsMagick
:make

Windows

It is possible to compile OSRA using either Cygwin or MinGW environment, however it appears that Cygwin-compiled executable runs about two orders of magnitude slower than a Linux version running on an equivalent class CPU. Therefore it is strongly recommended NOT to use Cygwin to compile OSRA.

Instructions for MinGW environment

Before you compile GraphicsMagick it is necessary to install the pre-requisite libraries - zlib, bzip2, jasper (I was able to compile only version 1.701.0 and not the later 1.900.1), jbigkit, jpeg-6b, lcms (1.19 not lcms2), libpng, tiff (3.8.2, not the later 3.9.3, 3.9.4).
You can read "ADD-ON LIBRARIES & PROGRAMS" for GraphicsMagick which seems to apply to ImageMagick as well.

Whenever "configure" script was available I used the following options:
:./configure --disable-shared LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include

To configure GraphicsMagick I used the following options:
:./configure --disable-shared --without-threads --disable-openmp LDFLAGS=-L/usr/local/lib/ CPPFLAGS=-I/usr/local/include/

Compile and install GraphicsMagick, GOCR (needs "make libs" for library), Potrace (needs ./configure --enable-libpotrace for library), TCLAP, OCRAD.

Compiling OpenBabel version 3.0.0:
First make sure zlib, eigen2, and libxml2 are installed. For libxml2 I used the following
options for configure: --without-threads --disable-shared;

Run cmake with the following options:
cmake.exe -G"MSYS Makefiles" -DZLIB_LIBRARY=/usr/local/lib/libz.a -DZLIB_INCLUDE_DIR=/usr/local/inclulde -DEIGEN2_INCLUDE_DIR=/usr/local/include/eigen2 -DLIBXML2_LIBRARIES=/usr/local/lib/libxml2.a -DLIBXML2_INCLUDE_DIR=/usr/local/include/libxml2 -DCMAKE_INSTALL_PREFIX=/usr/local/ -DBUILD_SHARED=OFF -DCMAKE_CXX_FLAGS=-DLIBXML_STATIC -DCMAKE_C_FLAGS=-DLIBXML_STATIC -DCMAKE_CXX_STANDARD_LIBRARIES=-lws2_32 ../
make
make install

Compiling poppler:
With MinGW one may need to edit poppler-global.h (lines 25-26) to remove dllimport and dllexport defines, also add to gfile.cc "#define _WIN32_WINNT 0x0501"

Compiling osra:

:./configure --with-openbabel-lib=/usr/local/bin --enable-static-linking
:make

Make sure you take a look at osra.bat to see that the environment is set
correctly. You will still need delegates.xml from ImageMagick installation
and a separately installed Ghostscript if you'd like to process PDF and
PostScript files.

Compiling OSRA v1.3.6 or earlier

Edit the Makefile to set ARCH variable to win32. Running make should (hopefully) generate osra.exe.
You're done!

Instructions for CygWin environment

OSRA CLI

Note: if you are going to link against certain libraries below statically (--enable-static-linking OSRA configuration option), then you need to choose the corresponding option.

  • GraphicsMagick (libGraphicsMagick3 and libGraphicsMagick-devel v1.3.12) and netpbm (libnetpbm and libnetpbm-devel v10.49.2) are part of CygWin. Install them.
  • Download GOCR v0.48 and install via ./configure && make libs install
  • Download OCRAD v0.21 and install via ./configure && make all install
  • Download POTRACE v1.9 and install:
  • As a static library ./configure --with-libpotrace --enable-static && make all install
  • As a dynamic library ./configure --with-libpotrace --enable-shared && make all install
  • Download TCLAP v1.2.0 and install via ./configure && make all install
  • Download OpenBabel v2.2.3, fix this (if appropriate), and install:
  • As a dynamic library via ./configure --enable-shared && make all install (needed to install header files)
  • As a static library ./configure --enable-static && make all install (will fail but after the static library is installed so don't care)

Java support

  • Download and unpack Sun SDK.
  • Install / compile [Dependencies] as mentioned above.
  • Set the JAVA_HOME variable to point to JDK (the path should not contain spaces or special characters):
    *:
    export JAVA_HOME=/cygdrive/c/Java/jdk1.6.0_27
  • Run ./configure (add any necessary configuration options):
./configure --enable-java --enable-static-linking --disable-graphicsmagick-config
  • Run make all install. Now library is available in src/libosra_java.dll.
  • Rename the library to osra_java.dll and copy it to either system-wide directory (e.g. C:\Windows\System32) or define java.library.path system property when starting Java:
java -Djava.library.path=C:\osra\src -cp commons-io-1.4.jar net.sf.osra.OsraLibTest

Related

Wiki: Dependencies
Wiki: Home