opencv undefined reference for CvSVM::predict(CvMat * const) - c++

I have encountered a strange problem about OpenCV 2.4.6.1.
The code is from http://www.opencv.jp/sample/svm.html.
I have link the project with
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_legacy -lopencv_nonfree -lopencv_optim
But it still has errors as follows:
undefined reference to `CvSVM::predict(CvMat const*) const'
collect2: ld returned 1 exit status
I have test with OpenCV 2.4.0 and OpenCV 2.4.5, both with these errors.
Could someone give me some advice, please? Thanks.

Related

Linking MKL in catkin_make / Cmake

I have a large codebase with multiple files and multiple Cmake files as well. The structure is src/folder1 src/folder2 etc and I run catkin_make -j1 from the src directory level. I am unable to link MKL. A small clip of the error is
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_sparse_d_xESB_SpMV_8_i4'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_zcoo0ssunc__mmout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_zcoo1ntuuf__mmout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_lp64_scsr0ntunc__smout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_lp64_ccsr0nd_nc__svout_seq'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_ccoo1stlnf__svout_seq'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_pds_pds_her_pos_fwd_ker_seq_nrhs_cmplx'
collect2: error: ld returned 1 exit status
I even added the following line to each cmake:
SET(GCC_COVERAGE_LINK_FLAGS " -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
The code does not use MKL BLAS directly but rather it is used by libraries like Opencv and Eigen (OpenCV was built with MKL).
I do define EIGEN_USE_MKL_ALL.
How do I link MKL?
You can make use of oneMKL link line advisor which recommends what are the required libraries and necessary compiler options for the use case on which you are working.
Here is the link
https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl/link-line-advisor.html

OpenCV SFM Module Reconstruct Method Linking Error

I want to use opencv sfm module.I installed sfm module with all dependencies.
I can use all opencv methods without reconstruct method.I have a problem with this method.I have linker error i searched on internet.But i couldn't solve the problem.
Link : compiling code with OpenCV Libraries
I found this and a lot of topic but i dont know how can i solve this problem
This is my cmake file:
project(x)
cmake_minimum_required(VERSION 3.6)
find_package(OpenCV REQUIRED)
include_directories(/usr/include/eigen3)
include_directories(/usr/local/include/opencv2/sfm)
set(OpenCV_LIBS -L. -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_video -lopencv_viz -lopencv_calib3d -lopencv_sfm -lpthread)
add_executable(x main.cpp)
target_link_libraries(x ${OpenCV_LIBS})
And this is error :
undefined reference to `cv::sfm::reconstruct(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, bool)'
collect2: error: ld returned 1 exit status
Can anyone help me?

Compiling libmodbus in Qt Creator on Windows throws undefined reference to '_imp_....' errors

I have the source .h and .c files for libmodbus (http://libmodbus.org/releases/libmodbus-3.0.6.tar.gz). I dumped them into my Qt Project after learning that Qt is smart enough to know the difference b/w c and c++ files.
I include modbus.h in main.cpp and I get about 50 errors (most of which are undefined reference errors). Note I did get libmodbus working in ubuntu using codeblocks and it was communicating fine. I'm trying this in windows now and both Qt and codeblocks seem to be angry at me.
Here is my .pro file.
QT += core
QT += widgets
QT -= gui
TARGET = testModBus
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QMAKE_CXXFLAGS += -w
QMAKE_CFLAGS += -w
SOURCES += main.cpp \
modbus.c \
modbus-data.c \
modbus-rtu.c \
modbus-tcp.c
HEADERS += \
config.h \
modbus.h \
modbus-private.h \
modbus-rtu.h \
modbus-rtu-private.h \
modbus-tcp.h \
modbus-tcp-private.h \
modbus-version.h \
zModBus.h \
inttypes.h \
stdint.h
And here is my Qt Output when I try to Compile:
18:03:02: Starting: "E:\Qt\Tools\mingw48_32\bin\mingw32-make.exe"
E:\Qt\5.2.1\mingw48_32\bin\qmake.exe -spec win32-g++ -o Makefile ..\testModBus\testModBus.pro
E:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/SSK/Desktop/qtProjects/build-testModBus-Desktop_Qt_5_2_1_MinGW_32bit-Release'
g++ -Wl,-s -Wl,-subsystem,console -mthreads -o release\testModBus.exe release/main.o release/modbus.o release/modbus-data.o release/modbus-rtu.o release/modbus-tcp.o -lglu32 -lopengl32 -lgdi32 -luser32 -LE:\Qt\5.2.1\mingw48_32\lib -lQt5Widgets -lQt5Gui -lQt5Core
release/modbus-tcp.o:modbus-tcp.c:(.text+0x24f): undefined reference to `_imp__select#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x2a3): undefined reference to `_imp__recv#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x2d7): undefined reference to `_imp__recv#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x30d): undefined reference to `_imp__shutdown#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x31c): undefined reference to `_imp__closesocket#4'
Makefile.Release:85: recipe for target 'release\testModBus.exe' failed
release/modbus-tcp.o:modbus-tcp.c:(.text+0x363): undefined reference to `_imp__setsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x394): undefined reference to `_imp__ioctlsocket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x3c6): undefined reference to `_imp__connect#12'
mingw32-make[1]: Leaving directory 'C:/Users/SSK/Desktop/qtProjects/build-testModBus-Desktop_Qt_5_2_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
release/modbus-tcp.o:modbus-tcp.c:(.text+0x3e2): undefined reference to `_imp__WSAGetLastError#0'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x444): undefined reference to `_imp__select#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x47f): undefined reference to `_imp__getsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x517): undefined reference to `_imp__send#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x597): undefined reference to `_imp__WSAStartup#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x624): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x65e): undefined reference to `_imp__htons#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x66f): undefined reference to `_imp__inet_addr#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x6c8): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x74c): undefined reference to `_imp__getaddrinfo#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x780): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x7bb): undefined reference to `_imp__freeaddrinfo#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x7d5): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x82f): undefined reference to `gai_strerrorW'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x8bc): undefined reference to `_imp__select#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x96c): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x9ab): undefined reference to `_imp__setsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0x9f0): undefined reference to `_imp__htons#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa0a): undefined reference to `_imp__inet_addr#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa2a): undefined reference to `_imp__bind#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa45): undefined reference to `_imp__listen#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa69): undefined reference to `_imp__htonl#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xa85): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xb38): undefined reference to `_imp__getaddrinfo#16'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xb89): undefined reference to `_imp__setsockopt#20'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xb99): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xbc8): undefined reference to `_imp__socket#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xbf9): undefined reference to `_imp__freeaddrinfo#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc23): undefined reference to `_imp__bind#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc33): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc63): undefined reference to `_imp__listen#8'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xc77): undefined reference to `_imp__freeaddrinfo#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xca5): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xcda): undefined reference to `gai_strerrorW'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xd61): undefined reference to `_imp__accept#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xd8b): undefined reference to `_imp__inet_ntoa#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xdc8): undefined reference to `_imp__closesocket#4'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xe19): undefined reference to `_imp__accept#12'
release/modbus-tcp.o:modbus-tcp.c:(.text+0xe57): undefined reference to `_imp__closesocket#4'
e:/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: release/modbus-tcp.o: bad reloc address 0x250 in section `.rdata'
e:/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [release\testModBus.exe] Error 1
mingw32-make: *** [release] Error 2
18:03:04: The process "E:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
You need to include ws2_32.lib in your dependencies. I.e. in your *.pro file add the line:
LIBS += -lws2_32
Turns out that the error was generated because of __declspec(dllexport) in one of the header files. Removed that and it went away. Then it started throwing a new error which is where I'm currently stuck at.

Qt and tesseract

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

Undefined reference when trying to compile a code with cmake

I'm trying to understand what's wrong with my cmake setup. I downloaded the code described in http://alexott.net/en/cpp/BoostAsioProxy.html. It's an asyncrhonous http proxy server using boost.
These are the contents of my CMakeLists.txt:
cmake_minimum_required(VERSION 2.4)
PROJECT(asio-proxy-async)
# Usage:
# cmake . -DCMAKE_INCLUDE_PATH=~/exp/include -DCMAKE_LIBRARY_PATH=~/exp/lib
#
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET (CMAKE_MODULE_PATH ${cpptests_SOURCE_DIR}/cmake CACHE PATH "local cmake")
ADD_DEFINITIONS(-g -Wall -ansi -Wno-deprecated)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREAD ON)
FIND_PACKAGE(Boost 1.49.0 REQUIRED COMPONENTS filesystem system thread regex)
MESSAGE(STATUS "** Boost Include: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARIES}")
IF(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ENDIF(Boost_FOUND)
SET(USED_LIBS ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY})
ADD_EXECUTABLE(asio-proxy-async proxy.cpp proxy-server.cpp proxy-conn.cpp)
TARGET_LINK_LIBRARIES(asio-proxy-async ${USED_LIBS})
After I type cmake . the 3 source files compile just ok, but then in the linking phase, I get this:
Linking CXX executable asio-proxy-async
/usr/bin/cmake -E cmake_link_script CMakeFiles/asio-proxy-async.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/asio-proxy-async.dir/proxy.o CMakeFiles/asio-proxy-async.dir/proxy-server.o CMakeFiles/asio-proxy-async.dir/proxy-conn.o -o asio-proxy-async -rdynamic -lboost_system-mt -lboost_thread-mt -lboost_regex-mt
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `error_code':
/usr/local/include/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `boost::asio::error::get_system_category()':
/usr/local/include/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `thread_exception':
/usr/local/include/boost/thread/exceptions.hpp:49: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy.o: In function `condition_error':
/usr/local/include/boost/thread/exceptions.hpp:82: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy-server.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
CMakeFiles/asio-proxy-async.dir/proxy-conn.o: In function `__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make[2]: *** [asio-proxy-async] Error 1
make[2]: Leaving directory `/home/nelsonrp/workspace/boost-test/asio-proxy-async'
make[1]: *** [CMakeFiles/asio-proxy-async.dir/all] Error 2
make[1]: Leaving directory `/home/nelsonrp/workspace/boost-test/asio-proxy-async'
make: *** [all] Error 2
I've seen a couple of posts here in SO talking about this kind of problems with cmake and boost, none of them with final answers though. To clarify things a bit more, let me just point out that if I do:
g++ -g -Wall -c proxy.cpp
g++ -g -Wall -c proxy-conn.cpp
g++ -g -Wall -c proxy-server.cpp
g++ proxy.o proxy-server.o proxy-conn.o -o asio-proxy-async -lboost_system -lboost_thread -lboost_regex -lboost_filesystem
The source compiles just fine, which means that I have boost installed and it is in the right place, the problem just seems to be with cmake. Any suggestions?
The source code archive available on the page ships with its own outdated version of the FindBoost.cmake module. Remove the outdated module file, whose path is asio-proxy-async/cmake/FindBoost.cmake, then re-create your build folder and run cmake again. This will make CMake use the standard FindBoost module which should have no problems finding your existing Boost installation.