4

I have no problem linking the dynamic opencv libraries, but I want to use static libraries instead, so I rebuilt OpenCV 2.3 with the "build shared libraries" option unchecked. I put the following on my .pro file

LIBS += "C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_calib3d231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_contrib231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_core231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_features2d231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_flann231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_gpu231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_imgproc231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_legacy231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_ml231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_objdetect231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_ts231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_video231.a"

INCLUDEPATH += "C:\Program Files\openCV_static\opencv\build\install\include"
INCLUDEPATH += "C:\Program Files\openCV_static\opencv\build\install\include\opencv"

This is very similar to what I had before when I was using the dynamic libraries, except the .a files actually ended in .dll .a, and I put the dll's (not the dll.a files) in the qt program's output directory (so the program could find them and run). Now the whole point is that I don't need those dlls, so they're no longer in my program's output directory (actually they didn't build with OpenCV). But I get these errors when I try to build my program:

C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x13): undefined reference to `AVIStreamRelease@4'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x25): undefined reference to `AVIStreamRelease@4'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x37): undefined reference to `AVIFileRelease@4'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN16CvCaptureCAM_VFW4openEi+0x6c): undefined reference to `capGetDriverDescriptionA@20'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN16CvCaptureCAM_VFW4openEi+0xb7): undefined reference to `capCreateCaptureWindowA@32'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN16CvCaptureAVI_VFW9grabFrameEv+0x29): undefined reference to `AVIStreamGetFrame@8'
.
.
.
.
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(grfmt_jpeg2000.obj):grfmt_jpeg2000.cpp:(.text$_ZN2cv13Jpeg2KEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x17b): undefined reference to `jas_stream_close'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(grfmt_jpeg2000.obj):grfmt_jpeg2000.cpp:(.text.startup._GLOBAL__sub_I_C__Program_Files_openCV_static_opencv_modules_highgui_src_grfmt_jpeg2000.cpp+0x4): undefined reference to `jas_init'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [release\trusion.exe] Error 1
mingw32-make.exe: *** [release] Error 2
23:21:10: The process "C:\MinGW\bin\mingw32-make.exe" exited with code 2.
Error while building project trusion (target: Desktop)
When executing build step 'Make'

I am using MinGW. Compiling the project with the same toolchain used to build opencv. Worked with dynamic libs, as mentioned above. Does not work with static libs.

Mat
  • 202,337
  • 40
  • 393
  • 406
jzepeda
  • 1,470
  • 2
  • 15
  • 22
  • Just a question: how did you manage to build opencv with Qt support? My build does not succeed because it expects a file named `qconfig.h` which did not come with my Qt source 4.6.3 download. Which version did you use? – vsz Apr 07 '12 at 16:22
  • @vsz sorry about the lateness. I did not attempt to build opencv with qt support. I simply import the opencv libraries to the qt program I'm writing. – jzepeda Apr 18 '12 at 02:48

1 Answers1

1

It seems you're missing Jasper dependency. OpenCV on Windows uses pre-built libjasper library (lib/libjasper*), try adding them to LIBS

For the 'undefined reference to AVIStreamRelease@4'error, try linking against vfw32.lib or MSVFW32.dll

Masci
  • 5,864
  • 1
  • 26
  • 21
  • thanks, that seems to be the tip of the iceberg. After that I also had to add libs jpeg, tiff and png. Now I'm getting errors like `\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x13): undefined reference to `AVIStreamRelease@4'` vfw related errors are what my web serches tell me, but how would I ago about addressing them? – jzepeda Mar 12 '12 at 02:02
  • thanks a lot! that did it.. i linked with Vfw32.lib. I had to download Windows 7 SDK First. – jzepeda Mar 12 '12 at 18:00
  • oh no! my bad, that actually didn't fix the problem... it actually didn't take the changes I made into account and was just going off on the latest succesful build. I added `"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\Vfw32.lib"` to the LIBS and also `INCLUDEPATH += "C:\Program Files\Microsoft SDKs\Windows\v7.1\Include` ... Two questions: Would linking this .lib with MinGW cause a problem, and, in the include path there is a Vfw.h, but there is also a Vfw.h on MinGW's include path.. would that cause a conflict? (In that case should I just not add it to the include path?) – jzepeda Mar 13 '12 at 06:43
  • also, adding `"C:\Windows\System32\msvfw32.dll"` to the LIBS gives me the same errors – jzepeda Mar 13 '12 at 06:43
  • I'm going to try and use visual studio instead to see if I can maybe bypass this problem. Now I'm facing different problems. Can you please take a look at [this question?](http://stackoverflow.com/questions/9697935/lnk2005-error-linking-static-opencv-libraries-with-visual-studio-and-qt-creator) – jzepeda Mar 14 '12 at 08:05