Tesseract: `make training` ld error when building 4.0 on macOS

Created on 10 Jul 2017  路  23Comments  路  Source: tesseract-ocr/tesseract

When I was compiling Tesseract 4.0 on macOS according compiling. At last step, make training came with the following error:

/bin/sh ../libtool  --tag=CXX   --mode=link g++-6  -g -O2 -std=c++11  -L/usr/local/opt/icu4c/lib -o text2image text2image.o libtesseract_training.la libtesseract_tessopt.la  -licui18n -licuuc  ../api/libtesseract.la -licui18n -licuuc -lpango-1.0 -lpangocairo-1.0 -lgobject-2.0 -lglib-2.0 -lcairo -lpangoft2-1.0 -lfontconfig  -L/usr/local/Cellar/leptonica/1.74.4/lib -llept
libtool: link: g++-6 -g -O2 -std=c++11 -o .libs/text2image text2image.o -Wl,-bind_at_load  -L/usr/local/opt/icu4c/lib ./.libs/libtesseract_training.a ./.libs/libtesseract_tessopt.a ../api/.libs/libtesseract.dylib -L/usr/local/Cellar/leptonica/1.74.4/lib -licui18n -licuuc -lpango-1.0 -lpangocairo-1.0 -lgobject-2.0 -lglib-2.0 -lcairo -lpangoft2-1.0 -lfontconfig -llept -fopenmp
ld: library not found for -lpango-1.0
collect2: error: ld returned 1 exit status
make[1]: *** [text2image] Error 1
make: *** [training] Error 2

I checked my lib in /usr/local/Cellar/pango/1.40.6/lib, libpango-1.0 was there.
So what's the problem?

question

Most helpful comment

I can't help more because I do not have a mac...

All 23 comments

What commands did you use to compile Tesseract?

@amitdo

brew install automake autoconf autoconf-archive libtool
brew install pkgconfig
brew install icu4c
brew install leptonica
brew install gcc
brew install gcc@6

git clone https://github.com/tesseract-ocr/tesseract/
cd tesseract
./autogen.sh
./configure CC=gcc-6 CXX=g++-6 CPPFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib
make -j
sudo make install
make training

It went wrong at last step(make training).

ld: library not found for -lpango-1.0

https://github.com/Homebrew/homebrew-core/blob/f7acb308d3ea/Formula/tesseract.rb#L36

You need also:
brew install pango

@amitdo How to use homebrew-core#L36?
I'v tried this command(brew install pango), it says pango has already been installed.
And I did find it under "/usr/local/Cellar/pango/1.40.6"
Thank you for your help~

I can't help more because I do not have a mac...

@amitdo Thanks~ I shall try it on Linux

@iChenwin,
Were you able to solve this issue?

cd tesseract/traing
vi Makefile

// Editing LDFLAGS
LDFLAGS = -L/usr/local/opt/icu4c/lib -L/usr/local/opt/pango/lib -L/usr/local/opt/gobject-introspection/lib -L/usr/local/opt/glib/lib -L/usr/local/opt/cairo/lib -L/usr/local/opt/fontconfig/lib
// insert a path to what you got ld error for the library path
make training
// no error will not be found.

i have the error symbol(s) not found for architecture x86_64 on make command. can any put some light on this.

@ameenudheen, which symbols are not found? I think the Tesseract user forum is a better place to get help for your problem.

macos related problem report in forum -
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/tesseract-ocr/M9kD-j9U1vA/ams7a3bdAAAJ

Thinking there might be something wrong happened during the 1300 lines of output, I ran make -j > makelog. Although most output went into the log file, these were printed onto the terminal:

/Library/Developer/CommandLineTools/usr/bin/ranlib: file: .libs/libtesseract_cutil.a(cutil_class.o) has no symbols

/Library/Developer/CommandLineTools/usr/bin/ranlib: file: .libs/libtesseract_cutil.a(cutil_class.o) has no symbols

networkio.cpp:55:15: warning: 'this' pointer cannot be null in well-defined C++

      code; comparison may be assumed to always evaluate to true

      [-Wtautological-undefined-compare]

  ASSERT_HOST(this != nullptr);

              ^~~~    ~~~~~~~

../../src/ccutil/errcode.h:84:30: note: expanded from macro 'ASSERT_HOST'

#define ASSERT_HOST(x) if (!(x))                                        \

                             ^

1 warning generated.

This looks like a broken installation: libpango-1.0.a or libpango-1.0.so exists, but is not in one of the directories where the linker is searching it. That implies that pkg-config --libs pango returns wrong information.

@stweil Thanks for your reply.

pkg-config --libs pango returns this:

-L/usr/local/Cellar/pango/1.42.1/lib -L/usr/local/Cellar/glib/2.56.1/lib -L/usr/local/opt/gettext/lib -L/usr/local/Cellar/fribidi/1.0.3/lib -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lintl -Wl,-framework -Wl,CoreFoundation -lfribidi

ls /usr/local/Cellar/pango/1.42.1/lib gives:

girepository-1.0          libpangocairo-1.0.0.dylib libpangoft2-1.0.a
libpango-1.0.0.dylib      libpangocairo-1.0.a       libpangoft2-1.0.dylib
libpango-1.0.a            libpangocairo-1.0.dylib   pkgconfig
libpango-1.0.dylib        libpangoft2-1.0.0.dylib

So the libpango-1.0.a exists, but I don't know where to find libpango-1.0.so. How can I find the paths the linker is searching for it? Should the .a and .so both exist or either one would be fine?

Have same error as ts. Not sure how to fix it.

@zdenop, I suggest to close this issue. Building on macOS works fine as long as people use the default compiler from Apple (not install their own gcc!) and only use the pre-build packages as described in the Wiki. I tested this on two different Macbooks with recent versions of macOS.

Please mark it also as _question_.

The wiki actually suggests to install gcc for homebrew.

Problem still exists, have to install Ubuntu 18.04. : (

I tried this and succeed:

./configure CC=gcc-9 CXX=g++-9 CPPFLAGS="-I/usr/local/opt/icu4c/include -I/usr/local/opt/pango/include" LDFLAGS="-L/usr/local/opt/icu4c/lib -L/usr/local/opt/pango/lib -L/usr/local/lib"

If it complain training tools cannot be built because cannot find icu, try add this configure: PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig

pkgconfig should find it also in local installation. If not - then this is not tesseract problem, but specific customization at build system we can not cover at tesseract (e.g. if user do custom installation from source, (s)he should be able to instruct pkgconfig to found needed component for tesseract)

Homebrew for macOS has some special requirements because it refuses to provide some software packages (icu4c, libarchive, libffi) at the usual places. The reason is that macOS provides that software, too, and Homebrew wants to avoid potential conflicts. Therefore it is necessary to set PKG_CONFIG_PATH, ideally when running configure. I updated the documentation for Homebrew in the Wiki.

The wiki actually suggests to install gcc for homebrew.

gcc was needed to get OpenMP support, but OpenMP has the known drawbacks that it costs much performance and only achieves a slightly reduced execution time. Therefore I changed the Wiki now.

@stweil : thank for this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dthrock picture dthrock  路  5Comments

johnthagen picture johnthagen  路  6Comments

clarkk picture clarkk  路  7Comments

anavc94 picture anavc94  路  6Comments

LaurentBerger picture LaurentBerger  路  3Comments