PDA

View Full Version : Couldn't link opencv with qt creator , this error happens



Being friendzoned sucks
2nd May 2014, 15:28
Hello,

I've been trying to solve this since yesterday with no luck,

first I downloaded the latest version of opencv , it came with it two folders , one is source and one is build I assumed build folder is the precompiled folder which is what I want, anyways I did this in the pro file:


INCLUDEPATH += C:/opencv/build/include
LIBS +=-LC:/opencv/build/x86/vc11/staticlib
CONFIG(debug, debug|release){
LIBS +=-lopencv_core249\
LIBS +=-lopencv_core249d\
LIBS +=-lopencv_highgui249\
LIBS +=-lopencv_highgui249d\
}

and it gives me this error:


:-1: error: LNK1104: cannot open file '+=-lopencv_core249d.obj'

when I delete
LIBS +=-lopencv_core249d\

it gives me the same error except it's for the highgui249d file.

Zlatomir
2nd May 2014, 20:30
The -l lib name option needs to be on the same line as the -L so you need a \, and also the debug/release are not supposed to be linked together, so the syntax should become something like:

CONFIG( debug, debug|release ) {
#debug libs
LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
-lopencv_core246d\
-lopencv_highgui246d
}
else {
#release libs
LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
-lopencv_core246\
-lopencv_highgui246
}

Being friendzoned sucks
2nd May 2014, 20:43
The -l lib name option needs to be on the same line as the -L so you need a \, and also the debug/release are not supposed to be linked together, so the syntax should become something like:

CONFIG( debug, debug|release ) {
#debug libs
LIBS += -LLIBS +=-LC:/opencv/build/x86/vc11/staticlib\
-lopencv_core246d\
-lopencv_highgui246d
}
else {
#release libs
LIBS += -LLIBS +=-LC:/opencv/build/x86/vc11/staticlib\
-lopencv_core246\
-lopencv_highgui246
}

well thanks buddy , now I have a new problem:

LNK1181: cannot open input file 'opencv_core246.lib'

when I compile in release mode and when I compile in debug mode it shows the same problem except for the debug file:

LNK1181: cannot open input file 'opencv_core246d.lib'

Zlatomir
2nd May 2014, 20:47
My bad, sorry, some copy/paste errors, i corrected the error in my previous post, and also you seem to have the 2.49 version of opencv (you can check the file names in that lib folder), so the code becomes:


CONFIG( debug, debug|release ) {
#debug libs
LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
-lopencv_core249d\
-lopencv_highgui249d
}
else {
#release libs
LIBS +=-LC:/opencv/build/x86/vc11/staticlib\
-lopencv_core249\
-lopencv_highgui249
}


LE: don't forget to run qmake after you modify the .pro file.

Being friendzoned sucks
2nd May 2014, 21:02
Yeah I fixed the copy thing before using it :D

but I'm stupid enough to forget about changing the names to the new version names..

anyways they're still some problems :(

first I added these to my pro file:


INCLUDEPATH += C:/opencv249/build/include/
CONFIG( debug, debug|release ) {
#debug libs
LIBS +=-LC:/opencv249/build/x64/vc11/staticlib\
-lopencv_core249d\
-lopencv_highgui249d
}
else {
#release libs
LIBS +=-LC:/opencv249/build/x64/vc11/staticlib\
-lopencv_core249\
-lopencv_highgui249
}

second here is the includes + code


#include<opencv/cv.h>
#include<opencv/highgui.h>

void MainWindow::showimage1(){
IplImage*img=cvLoadImage("C:\\Users\\myuser\\QT\\build-CaptureTools-Unnamed-Debug\\Fri May 2 2014_3039.png");
cvNamedWindow("example",CV_WINDOW_AUTOSIZE);
cvShowImage("example",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("example");

}

------------------------------------------

first I'll start with the notifications that it shows in the issues section along with the errors:


C:\opencv249\build\include\opencv2\flann\logger.h: 66: warning: C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

C:\opencv249\build\include\opencv2\flann\logger.h: 66: warning: C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

C:\opencv249\build\include\opencv2\flann\logger.h: 66: warning: C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.


-----------------------------------------------------

the errors:


mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvReleaseImage referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvNamedWindow referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvShowImage referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvDestroyWindow referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvLoadImage referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvWaitKey referenced in function "public: void __thiscall MainWindow::showimage1(void)" (?showimage1@MainWindow@@QAEXXZ)

debug\CaptureTools.exe:-1: error: LNK1120: 6 unresolved externals

Zlatomir
2nd May 2014, 21:15
Are you trying to build using the same compiler as opencv version? (from the opencv path is seems to be vc11, that means Visual Studio 2012)

Being friendzoned sucks
2nd May 2014, 21:58
yes I've tried woith many compilers but it didn't work , including msvc 11

Added after 37 minutes:

Hello zlatomir are you there ? :(

I found this:

http://stackoverflow.com/questions/18313769/opencv-unresolved-external-symbol-error-in-visual-studio

maybe it's similar to my problem but I couldn't understand his solution ?

I'm using qt 5.1.1 built it statically and using x86 msvc11 , my windows is 64bit if this is important , anyways the problem is still happens.. when I use the x86 libraries like this:
LIBS +=-LC:/opencv249/build/x86/vc11/staticlib\

it shows a lot of errors most of them are called " mismatch "

Zlatomir
2nd May 2014, 22:14
Use the x86 folder if you built x86 Qt, don't forget to run qmake after you modify the .pro file, and also for static linkage you should add some more libraries:


INCLUDEPATH += C:/opencv249/build/include/
CONFIG( debug, debug|release ) {
#debug libs
LIBS +=-LC:/opencv249/build/x86/vc11/staticlib\
-lopencv_core249d\
-lopencv_highgui249d\
-lIlmImfd\
-llibpngd\
-llibjpegd\
-llibjasperd\
-lIlmImfd\
-lzlibd
}
else {
#release libs
LIBS +=-LC:/opencv249/build/x86/vc11/staticlib\
-lopencv_core249\
-lopencv_highgui249\
-lIlmImf\
-llibpng\
-llibjpeg\
-llibjasper\
-lIlmImf\
-lzlib
}

Being friendzoned sucks
2nd May 2014, 22:22
Thanks , still the same problem if I used the x64 folder , and when I use the x86 it shows me about 180 errors most of them are mismatch , like this error:

opencv_core249d.lib(array.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj

Zlatomir
2nd May 2014, 22:41
Just for testing try to link with dynamic opencv (use the x86 folder and lib instead of staticlib)

Being friendzoned sucks
2nd May 2014, 22:50
when using both x64 folder and x86 after applying what you've said this error happens:

Qt5Widgetsd.lib(qapplication.obj):-1: error: LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

well I think it's working :D

thanks man

but why can't I use the static lib ? does that mean I have to include the files to my exe program ? how can I build it statically ?

ChrisW67
4th May 2014, 01:39
Just for the record the reason for the failure in the first post is the trailing backslashes on line 4 through 7. The line starting at 4 effectively becomes:


LIBS +=-lopencv_core249 LIBS +=-lopencv_core249d LIBS +=-lopencv_highgui249 LIBS +=-lopencv_highgui249d }

Leading the linker to try to look for a file literally called "+=-lopencv_core249d" that does not exist.