Machine Learning Library OpenCV
-
i've tried to compile the CvEM example of the documentation (http://opencv.willowgarage.com/wiki/MachineLearning#Expectation-Maximization). i've set the library search path to opencv\lib and also the include path. i inlcude the -lml machine learning library however i got the following error:
undefined reference to `CvEM::CvEM()'
// CvEM em_model; CvEMParams params;
if i comment CvEM em_model the code compiles - CvEMParams doesn't result in an error. so i think that i didn't have problems with the include paths!? does anyone know how to solve this problem? thank you in advance
Also if i run the code in Visual Studio, it runs perfectly. best regards
-
I gather that the code actually compiles fine, but fails at the linking stage? As you mention, that implies that your INCLUDE path is fine (especially since it's correctly finding the definition of the CvEMParams struct). Can you paste in the actual linker command that is failing?
-
Thank you Chris, here is the compilation output.
@
Running build steps for project Check...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directoryC:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\mainwindow.o ..\Check\mainwindow.cpp g++ -mthreads -Wl,-subsystem,windows -o debug\Check.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\QtSDK\Desktop\Qt\4.7.4\mingw\lib" -lmingw32 -lqtmaind -LC:/OpenCV2.1/bin -lcv210 -lcxcore210 -lcvaux210 -lhighgui210 -lml210 -lcxts210 -lnetapi32 -lQtGuid4 -lQtCored4 -LC:\OpenSSL-Win32_full\lib debug/mainwindow.o: In functionMainWindow':
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference toCvEM::CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:49: undefined reference toCvEM::train(CvMat const*, CvMat const*, CvEMParams, CvMat*)'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:59: undefined reference toCvEM::predict(CvMat const*, CvMat*) const' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference toCvEM::CvEM()'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:49: undefined reference toCvEM::train(CvMat const*, CvMat const*, CvEMParams, CvMat*)' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:59: undefined reference toCvEM::predict(CvMat const*, CvMat*) const'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()' mingw32-make[1]: Leaving directoryC:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to `CvEM::~CvEM()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\Check.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project Check (target: Desktop)
When executing build step 'Make' @ -
I haven't noticed that, but for some bizarre reason it runs perfectly with the above syntax. I changed to /lib and same problem still persist. Here is the new compilation code
@Running build steps for project Check...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directoryC:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug' c:\QtSDK\Desktop\Qt\4.7.4\mingw\bin\uic.exe ..\Check\mainwindow.ui -o ui_mainwindow.h g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\main.o ..\Check\main.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\mainwindow.o ..\Check\mainwindow.cpp C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -D__GNUC__ -DWIN32 ..\Check\mainwindow.h -o debug\moc_mainwindow.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp g++ -mthreads -Wl,-subsystem,windows -o debug\Check.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\QtSDK\Desktop\Qt\4.7.4\mingw\lib" -lmingw32 -lqtmaind -LC:/OpenCV2.1/lib -lcv210 -lcxcore210 -lcvaux210 -lhighgui210 -lml210 -lcxts210 -lnetapi32 -lQtGuid4 -lQtCored4 -LC:\OpenSSL-Win32_full\lib mingw32-make[1]: Leaving directoryC:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop_-MinGW_4_4__Qt_SDK__Debug'
debug/mainwindow.o: In functionMainWindow': C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference toCvEM::CvEM()'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference toCvEM::CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()'
C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to `CvEM::~CvEM()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\Check.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project Check (target: Desktop)
When executing build step 'Make'@ -
Ordinarily the linker will tell you if it can't find a library, so presumably it is in fact finding cv210 someplace, but wherever it is, it does not actually contain the definition of the CvEM class. Did you compile it yourself, or download a binary? I'm not sure how to examine the contents of a library on windows, but on Linux and Mac the "nm" command will list all the symbols defined in there: you could grep that list for CvEM to make sure it's in there.
-
I downloaded it and didn't compile the library myself. The weird thing, if i copy/paste my code on visual studio, it runs perfectly without any problems which indicates the CvEM is there.
Is it possible that ml210.lib compiled file is compatible with VS2010 and not with Qt, so maybe i need to compile the file myself ? (sorry for the noob question, i am not really experienced there)
-
-
Hello Chris,
I finally solved the issue. I just recompiled opencv with mingw (which qt uses) . Despite there were some libraries that worked with the cmake for vs2010 but apparently the one i wanted didn't.
Hope the solution help some other dude.
Cheers