[Solved] Cannot link libs statically
-
wrote on 23 Feb 2015, 18:56 last edited by liimyd
Hello,
I've been attempting to deploy a static application with Windows, and have already built Qt statically. I was following "this":http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW tutorial, and I created a kit using my dynamic Qt's mingw32 compiler and my static Qt's qmake from C:\Qt\Static\5.2.0\bin, which was created during the static build. However, when I try to run the project, I get several errors with the OpenCV libraries that I'm trying to link, such as "cannot find -lopencv_calib3d300".
The ridiculous part is that I have no issues running this project if I switch the kit to another which uses the same compiler, but a different qmake, so I'm pretty sure that my .pro file is correct. I'm not sure if the qmake that comes with the static build is causing issues or if it's something else. I'd really appreciate it if someone could help me figure out this issue!
Edit: The solution to cvLog and cvCartToLog - the order in which you list your static libraries in your .pro file matters. I used Dependency Walker to figure out which order they had to be placed in.
-
Hi and welcome to devnet,
Maybe a silly question but do you have different rules in your pro file for when you do static build ? Are you somehow not adding -L/path/to/OpenCV to LIBS when in static mode ?
-
wrote on 23 Feb 2015, 23:10 last edited by
Hi,
I am using the same pro file for dynamic and static build, here's how I link the openCV files:
@
CONFIG += staticINCLUDEPATH += C:\Programs\opencvMinGW\install\include
LIBS += -LC:\Programs\opencvMinGW\install\x64\mingw\bin
-lopencv_calib3d300
-lopencv_core300
-lopencv_features2d300
-lopencv_flann300
-lopencv_highgui300
-lopencv_imgcodecs300
-lopencv_imgproc300
-lopencv_ml300
-lopencv_objdetect300
-lopencv_photo300
-lopencv_shape300
-lopencv_stitching300
-lopencv_superres300
-lopencv_video300
-lopencv_videoio300
-lopencv_videostab300@
The libraries were created with CMake with OpenCV 3.0
-
Looks fine
Can you show the exact compilation errors you have ?
On a side note, you can use the unix notation in the pro files even on Windows
-
wrote on 24 Feb 2015, 00:42 last edited by
There's 17 errors, one for each of the OpenCV libaries that I try to link. They're all the same except for the name of the lib. Here's just the first one:
C:/Qt/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lopencv_calib3d300
-
Did you check the compiler output panel to see what you have as -L parameters ?
-
wrote on 28 Feb 2015, 21:13 last edited by
Sorry for the slow reply! It was a busy week for school.
This is what my compiler output says right before I get the errors, I'm not too sure what you mean by the -L parameters, is this it?
g++ -static -static-libgcc -Wl,-s -Wl,-subsystem,windows -mthreads -o release\blood_visual.exe release/main.o release/mainwindow.o release/contours.o release/edge.o release/blood_visual_plugin_import.o release/moc_mainwindow.o release/moc_contours.o release/moc_edge.o -lmingw32 -LC:/Qt/Static/5.3/lib -lqtmain -LC:\Programs\opencvMinGW\install\x64\mingw\bin -lopencv_calib3d300 -lopencv_core300 -lopencv_features2d300 -lopencv_flann300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_imgproc300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_shape300 -lopencv_stitching300 -lopencv_superres300 -lopencv_video300 -lopencv_videoio300 -lopencv_videostab300 -LC:/Qt/Static/5.3/plugins/accessible -lqtaccessiblewidgets -lQt5Widgets -LC:/Qt/Static/5.3/plugins/platforms -lqwindows -lwinspool -lshlwapi -lQt5PlatformSupport -LC:/Qt/Static/5.3/plugins/imageformats -lqdds -lqicns -lqico -lqjp2 -lqmng -lqtga -lqtiff -lqwbmp -lqwebp -lQt5Gui -lcomdlg32 -loleaut32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32
-
-L is used to give the linker additional folders to search for libraries. It seems that you didn't add the folder where the OpenCV libraries are located.
-
wrote on 28 Feb 2015, 23:37 last edited by
I'm slightly confused. From one of my previous posts above, didn't I correctly link the OpenCV folder containing the libraries in my .pro file? Or was I supposed to do it another way?
-
Where is opencv_calib3d300.lib located on your computer ?
-
wrote on 28 Feb 2015, 23:56 last edited by
They're all in C:\Programs\opencvMinGW\install\x64\mingw\bin, which was made with CMake.
Perhaps I'm using the wrong types of libraries? All of the openCV files in that folder have a format like "libopencv_calib3d300.dll", for instance. Maybe I'm not supposed to be using .dll files? It works fine with my other kit though.
-
You don't link to dlls you link to lib files, where are these located ?
-
wrote on 1 Mar 2015, 00:10 last edited by
Ahhhhhhhh I see... :(
Yes, those should be in C:\Programs\opencv\build\x86\vc12\staticlibNow I know why the folder was called "staticlib"... I will try this later! Thank you!!
-
Not so fast ! Since you have dlls you probably have a second set of these in another folder. On Windows, the static libraries and the import libraries have the same extension...
-
wrote on 1 Mar 2015, 07:49 last edited by
I can't find another folder containing the libs (neither in the original opencv folders, nor in the folders created by CMake), and as you predicted, the libraries in staticlib didn't work. Where can I go from here?
-
I just realized: C:\Programs\opencv\build\x86\vc12\staticlib
That means that these libs are for Visual Studio not MinGWUnless you built OpenCV yourself, just grab the archive again
-
wrote on 2 Mar 2015, 06:41 last edited by
Sorry, I don't quite understand. After I re-downloaded the package for opencv 3.0, I only had files with a .lib extension in the staticlib folder, which you already said not to use, and in C:\Programs\opencv\build\x86\vc12\lib, which only has opencv_ts300 and opencv_world300 (I don't know how to use these). I can't seem to find any other .lib files.
-
Then where did you get the dlls from ?
-
wrote on 3 Mar 2015, 01:18 last edited by
The dlls were created with cmake, but I couldn't find the regular libraries from the cmake-generated folders. Do I have to rebuild opencv with cmake? I was using the cmake-gui and there were a lot of different options that I could check or uncheck. Maybe some of them will build the regular libraries?
-
If the dlls were created with cmake then you already built it by hand so you should have the corresponding lib files somewhere
1/24