Qt and tesseract - c++

I want to use the tesseract with qt 5 + mingw. I downloaded vc++ libs fir from here
in my application i did:
#include "tesseract/baseapi.h"
...
tesseract::TessBaseAPI *OCRbase = new tesseract::TessBaseAPI();
if (!OCRbase->Init(NULL,"eng",tesseract::OEM_DEFAULT))
{
qDebug() << "tesseract init error";
return;
}
but this code gives me such errors:
testOCR/dialog.cpp:57: undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'
debug/dialog.o: In function `ZN9tesseract11TessBaseAPI4InitEPKcS2_NS_13OcrEngineModeE':
testOCR/tesseract-3.02.02-win32-lib-include-dirs/include/tesseract/baseapi.h:208: undefined reference to `tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool)'
collect2.exe: error: ld returned 1 exit status
My .pro file is look like this:
INCLUDEPATH += $$PWD\tesseract-3.02.02-win32-lib-include-dirs\include
LIBS += -L$$PWD\tesseract-3.02.02-win32-lib-include-dirs\lib -llibtesseract302-static-debug
LIBS += -L$$PWD\leptonica\lib -lliblept
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
FORMS += dialog.ui
I spent a lot of time trying to link this, is there something im doing wrong?

I did manage to compile tesseract with mingw myself but after i tried to link it with my test application i got a lot of:
tesseract-ocr\ccutil\tprintf.cpp:56: ошибка: undefined reference to `_Unwind_Resume'
and
pageiterator.cpp:-1: ошибка: undefined reference to `__gxx_personality_v0'
errors. What does that means? in my pro file this time i did add
LIBS += -L$$PWD\lib -llept -ltesseract -ltiff -lwebp -lgif -lpng -ljpeg -lzlib125-static-mtdll-debug
LIBS += lws2_32

Related

How do I fix "undefined reference" errors in my Qt-Creator project while linking the ffmpeg library "libav"?

I'm currently trying to use the libav library from FFmpeg in my Qt-Creator project, but I get over a thousand "undefined reference to ..." errors and I have no idea what I'm doing wrong. The errors don't depend on the actual code, because I changed it a few times, but as long as I use methods of the library these errors occur.
I have also tried to run the code in Visual Studio and that worked.
My project-file looks like this:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\include
SOURCES += \
Main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
QMAKE_CXXFLAGS += -D__STDC_CONSTANT_MACROS
LIBS += -lMfuuid
LIBS += -lStrmiids
LIBS += -lMfplat
LIBS += -lBcrypt
LIBS += -lSecur32
LIBS += -lWs2_32
LIBS += -pthread
LIBS += -L"D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib"
LIBS += -lavdevice
LIBS += -lavfilter
LIBS += -lavformat
LIBS += -lavcodec
LIBS += -lswresample
LIBS += -lswscale
LIBS += -lavutil
HEADERS += \
wrapper.h
The library files are stored at D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib. The errors I get when running the program look something like this (extract).
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/aviobuf.o):(.text$mn+0x16): undefined reference to `__security_cookie'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/aviobuf.o):(.xdata[$unwind$ff_read_string_to_bprint_overwrite]+0x1c): more undefined references to `__GSHandlerCheck' follow
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/4xm.o):(.text$mn+0x250): undefined reference to `__security_check_cookie'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.text$mn+0x2fe): undefined reference to `sscanf'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.text$mn+0x33f): undefined reference to `sscanf'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.text$mn+0x65b): undefined reference to `__report_rangecheckfailure'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.text$mn+0x18): undefined reference to `__security_cookie'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.text$mn+0x97): undefined reference to `__security_check_cookie'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.text$mn+0x14d): undefined reference to `__report_rangecheckfailure'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.xdata[$unwind$yuv4_read_header]+0x20): undefined reference to `__GSHandlerCheck'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/yuv4mpegdec.o):(.xdata[$unwind$yuv4_read_packet]+0x18): undefined reference to `__GSHandlerCheck'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/xwma.o):(.text$mn+0x14): undefined reference to `__security_cookie'
:-1: Fehler: D:\Programme\ffmpeg-source\ffmpeg-5.1.2\vs2019_build\lib/libavformat.a(libavformat/xwma.o):(.text$mn+0x2e0): undefined reference to `__security_check_cookie'
...
Is a library missing? Am I including the lMfuuid, Strmiids, Mfplat, etc. the wrong way? If you have any idea I would be very grateful. I'm really confused. I'm using the MinGW64 compiler.

DLIB and QT under windows. SVM multiclass training unlinked reference

I am trying to build the example provided by dlib for multiple class SVM training using QT on windows. (the example is available at this link: http://dlib.net/multiclass_classification_ex.cpp.html)
first of all I took the DLIB .lib files from a prebuilt library using MS visual studio, and took the include files and modified the QT .pro file to be as follows.
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
INCLUDEPATH += $$PWD/dlib/include
debug {
LIBS += -L$$PWD/dlib/lib -ldlib_debug_64bit_msvc1900
}
!debug {
LIBS += -L$$PWD/dlib/lib -ldlib_release_64bit_msvc1900
}
when i try building the code i get the following errors:
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::~thread_pool_implementation()'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::shutdown_pool()'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::thread_pool_implementation(unsigned long)'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::num_threads_in_pool() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::num_threads_in_pool() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::find_empty_task_slot() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::make_next_task_id(long)'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::wait_for_all_tasks() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::is_worker_thread(unsigned long) const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::find_empty_task_slot() const'
C:\Users\Administrator\Documents\SVMDlib\main.cpp:-1: error: undefined reference to `dlib::thread_pool_implementation::~thread_pool_implementation()'
collect2.exe:-1: error: error: ld returned 1 exit status
knowing that i tried to run the simple SVM code (provided here: http://dlib.net/svm_ex.cpp.html) it compiled and ran perfectly.
Am I missing a library of some kind? as all the errors are linking error and undefined references?

Getting undefined reference related to levelDB in C++ program despite including the library in QT Creator (in Ubuntu 16.04)

These are the errors that I'm getting while building the c++ project in QT Creator:
error: undefined reference to `leveldb::DestroyDB(std::string const&, leveldb::Options const&)'
error: undefined reference to `leveldb::RepairDB(std::string const&, leveldb::Options const&)'
error: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
error: undefined reference to `leveldb::Status::ToString() const'
Earlier, additionally, I was getting tens of similar libcurl undefined reference errors, but I fixed the errors after using the "add library" and selecting the "System Library" option, which automatically included the following line to the .pro file:
unix|win32: LIBS += -lcurl
So, I tried the same thing for leveldb, which has automatically included the following line in the .pro file:
unix|win32: LIBS += -lleveldb
But despite that, the errors are still there.

QT creator with mingw, glew linking errors

I've been trying for around 3/4 days to link glew with qt creator, but I´m unable to.
I've tried with msvc and mingw 64 & 32 bits.
Right now I´m using mingw 32 bits, and also a 32bits glew compiled with mingw.
This is the code in my .pro file:
QT += core gui opengl
CONFIG += c++11
INCLUDEPATH += C:/lib/glew-gcc-debug-1.10.0-win32/include/GL
LIBS += -lglew32.dll -LC:/lib/glew-gcc-debug-1.10.0-win32/bin -LC:/lib/glew-gcc-debug-1.10.0-win32/lib
TARGET = Test
TEMPLATE = app
SOURCES += \
glslprogram.cpp \
glutils.cpp \
main.cpp \
mainview.cpp \
mainwindow.cpp \
sceneLine.cpp \
dialog.cpp \
viewpositiondialog.cpp
HEADERS += \
glslprogram.h \
glutils.h \
mainview.h \
scene.h \
mainwindow.h \
sceneLine.h \
dialog.h \
viewpositiondialog.h
FORMS += \
dialog.ui \
viewpositiondialog.ui
OTHER_FILES += \
shader/scenebasic2.dat
and this is is the output:
g++ -Wl,-subsystem,windows -mthreads -o debug\Test.exe object_script.Test.Debug -lmingw32 -LC:/Qt/Qt5.5.0/5.5/mingw492_32/lib -lqtmaind -lshell32 -lglew32.dll -LC:/lib/glew-gcc-debug-1.10.0-win32/bin -LC:/lib/glew-gcc-debug-1.10.0-win32/lib -lQt5OpenGLd -lQt5Widgetsd -lQt5Guid -lQt5Cored
./debug\glutils.o: In function `ZN7GLUtils19checkForOpenGLErrorEv':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:34: undefined reference to `glGetError#0'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:39: undefined reference to `glGetError#0'
Makefile.Debug:112: recipe for target 'debug\Test.exe' failed
./debug\glutils.o: In function `ZN7GLUtils10dumpGLInfoEb':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:46: undefined reference to `glGetString#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:47: undefined reference to `glGetString#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:48: undefined reference to `glGetString#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:49: undefined reference to `glGetString#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:52: undefined reference to `glGetIntegerv#8'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:53: undefined reference to `glGetIntegerv#8'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/glutils.cpp:63: undefined reference to `glGetIntegerv#8'
./debug\mainview.o: In function `ZN8MainView12initializeGLEv':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/mainview.cpp:113: undefined reference to `glClearColor#16'
./debug\sceneLine.o: In function `ZN9SceneLine9initSceneEv':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:279: undefined reference to `glClearColor#16'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:280: undefined reference to `glEnable#4'
./debug\sceneLine.o: In function `ZN9SceneLine6renderEPf':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:325: undefined reference to `glClear#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:336: undefined reference to `glDrawArrays#12'
./debug\sceneLine.o: In function `ZN9SceneLine6renderEdPf':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:350: undefined reference to `glClear#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:360: undefined reference to `glDrawArrays#12'
./debug\sceneLine.o: In function `ZN9SceneLine6renderEddddddPf':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:393: undefined reference to `glClear#4'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:417: undefined reference to `glDrawArrays#12'
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:421: undefined reference to `glDrawArrays#12'
./debug\sceneLine.o: In function `ZN9SceneLine6resizeEii':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/sceneLine.cpp:441: undefined reference to `glViewport#16'
./debug\sceneLine.o: In function `ZN5SceneC2Ev':
C:\Development\test\build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug/../Test/scene.h:4: undefined reference to `vtable for Scene'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: Leaving directory 'C:/Development/test/build-Test-Desktop_Qt_5_5_0_MinGW_32bit-Debug'
makefile:34: recipe for target 'debug' failed
Hope someone can help.

OpenCV 2.3 Compiling Issue - Undefined Refence - Ubuntu 11.10

System Info:
Ubuntu 11.10 (64 bits) with OpenCV 2.3 (installed today)
I'm trying to compile some very simple code in OpenCV 2.3 but I'm getting a weird error.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(){
cv::Mat image=cv::imread("img.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image",image);
cv::waitKey(0);
return 1;
}
however, I'm getting these error messages...
-SG41:~/Desktop$ g++ `pkg-config opencv --cflags --libs` -o test_1 test_1.cpp
/tmp/ccCvS1ys.o: In function `main':
test_1.cpp:(.text+0x44): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test_1.cpp:(.text+0x8e): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test_1.cpp:(.text+0xbc): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test_1.cpp:(.text+0xf0): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test_1.cpp:(.text+0x112): undefined reference to `cv::waitKey(int)'
/tmp/ccCvS1ys.o: In function `cv::Mat::~Mat()':
test_1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccCvS1ys.o: In function `cv::Mat::release()':
test_1.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
I am guessing that at least some of the libraries in the output of
pkg-config opencv --libs
are archive libraries. It is incorrect to put archive libraries before sources that need them (test_1.cpp in this case): the order of sources and libraries on the link line matters.
Try
g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`
I was having the same problem, but I found out pkg-config opencv --cflags is printing "-I/usr/include/opencv" instead of "-I/usr/include/opencv2"... Maybe a package bug on Ubuntu?
I am using cmake and had similar problems.
Something weird is going on with the cmake configuration files.
For me the problems were solved by simply setting OPENCV_FOUND to TRUE and OpenCV_FOUND to TRUE.
Also I had to set OpenCV_DIR to /usr/local/share/OpenCV.
See also CMake error configuring opencv
#EmployedRussian 's answer worked for me too. For those who are wondering how to specify this command in Eclipse, use this post -
https://www.eclipse.org/forums/index.php?t=msg&goto=233377&
Instead of adding gtk+, use opencv;
Instead of adding the new flags to 'Miscellaneous linker flags', add the new flags at the end after ${INPUT} in -
Project->Right click->Properties->C/C++ Build ->Settings->GCC C++ linker->Expert Settings: command line pattern