Undefined reference error in C++/Qt

719 Views Asked by At

I am trying to include Tesseract OCR library into my Qt project. I have done everything according to instructions, but it doesn't work.

tesseract::TessBaseAPI *myOCR =
            new tesseract::TessBaseAPI();

Error - undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'

As I think, it's linking problem, but I'm not sure. Take a look of .pro file (only necessary code):

unix|win32: LIBS += -L$$PWD/../../Tesseract-OCR/lib/ -llibtesseract302

INCLUDEPATH += $$PWD/../../Tesseract-OCR/include/tesseract
DEPENDPATH += $$PWD/../../Tesseract-OCR/include/tesseract

win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../Tesseract-OCR/lib/libtesseract302.lib

unix|win32: LIBS += -L$$PWD/../../Tesseract-OCR/lib/ -lliblept168

INCLUDEPATH += $$PWD/../../Tesseract-OCR/include/leptonica
DEPENDPATH += $$PWD/../../Tesseract-OCR/include/leptonica

win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../Tesseract-OCR/lib/liblept168.lib

DEFINES += _tagBLOB_DEFINED
DEFINES += USE_STD_NAMESPACE
DEFINES += WINDLLNAME=\\\"lib$$TARGET.dll\\\"
DEFINES += VERSION=\\\"$$VERSION\\\"
DEFINES -= UNICODE

INCLUDEPATH += C:/Tesseract-OCR/tesseract-ocr/api
INCLUDEPATH += C:/Tesseract-OCR/tesseract-ocr/ccmain
INCLUDEPATH += C:/Tesseract-OCR/tesseract-ocr/ccutil
INCLUDEPATH += C:/Tesseract-OCR/tesseract-ocr/ccstruct
INCLUDEPATH += C:/Tesseract-OCR/tesseract-ocr/include

LIBS += C:/Tesseract-OCR/lib/liblept168-static-mtdll.lib
LIBS += C:/Tesseract-OCR/lib/giflib416-static-mtdll.lib
LIBS += C:/Tesseract-OCR/lib/libjpeg8c-static-mtdll.lib
LIBS += C:/Tesseract-OCR/lib/libtiff394-static-mtdll.lib
LIBS += C:/Tesseract-OCR/lib/zlib125-static-mtdll.lib

Every function of TessBaseAPI has the same error.

1

There are 1 best solutions below

0
On

First: "undefined reference" means liker can not find appropriate static library, so look into this direction.

According to this, this and this Tesseract needs libtesseract.lib (.a) but also liblept.lib (.a).

I recommend to not be very fancy with your .pro file at first and just try to build and run a bare minimum (and I suspect it needs only these two libraries and probably some DLLs).

Also I recommend to specify libraries you want to link in .pro file like this:

LIBS += -L" C:/Tesseract-OCR/lib/" -llept

or even better like this (if your libraries are copied inside your project folder)

LIBS += -L" $$_PRO_FILE_PWD_/Tesseract-OCR/lib/" -llept

but not like this

LIBS +=  C:/Tesseract-OCR/lib/liblept.lib