My end goal is to have a portable Opencv program that I can easily install and use on other Windows computers. I have successfully written the program using codeblocks and Mingw.
Currently I have a functioning program that uses OpenCV's dynamic linked libraries. But when I move the executable anywhere, it can't find the dlls.
I have attempted to use static libraries so that I don't have to install Opencv on the computers that will be running the program, and everything can run from the executable. The following are the steps I took.



When I build this, I get a series of "undefined reference to 'xxxxx'" errors.
e.g.
Build Messages
C:\opencv\build\x64\mingw (static)\staticlib\libopencv_core2410.a(persistence.cpp.obj):persistence.cpp:(.text$_ZL12icvCloseFileP13CvFileStorage+0x5a)||undefined reference to `gzclose'|
Build Log
C:\opencv\build\x64\mingw (static)\staticlib\libopencv_core2410.a(persistence.cpp.obj):persistence.cpp:(.text$_ZL12icvCloseFileP13CvFileStorage+0x5a): undefined reference to `gzclose'
If you have any advice for these errors, it would be greatly appreciated.
I have also been thinking that it is possible that I am going about this all wrong (I have a degree in electrical engineering, so I was exposed to a lot of programming; however, I may have missed out on some basic software engineering components.)
Here are some other things I have considered:
Using Visual Studios - The libraries for opencv are precompiled and also the target computers run windows so this might seem logical - I experimented a little bit and became frustrated with Visual Studios. I am becoming a Linux enthusiast and do not want to waste time learning windows specific programming.
Use Visual Studios Compiler in Codeblocks - The only option in Codeblocks is to use Visual C++ 2010 - I can't seem to get to get VC11 or VC12 to be used in CodeBlocks. Also, I see Visual C++ installed, but can't seem to locate its folder. (In Summary, I tried a few things that didn't yield immediate positive results)
Use an installer - I don't have experience with installers, but perhaps it is easier than trying to link libraries into an exectuatble. I am under the impression that one can set up an installer to store all dependencies in Program Files and put a shortcut to the executable in a convenient place. Is this the case, and what degree of difficulty is involved?
Manually organize a portable folder with dependencies. Not much experience with this, but again, maybe easier than linking libraries.
Please feel free to comment on the other options or provide any solution that I may be missing.
Set the compiler as the one you use for building OpenCV static library maybe the solution.
For example, I build OpenCV with MinGW 4.7.1, then I should set compiler in Code Blocks to the same compiler (MinGW 4.7.1).
I had problems too getting a stand-alone .exe file with the combination of OpenCV3.1.0, CMake3.4.2, MinGW5.3.0 using code:blocks. As I am relatively new to OpenCV and c++ in general, the solution is maybe more complicated than it has to be, but at least for me it works. My solution worked as follows:
Make static libraries, as you did it, with BUILD_SHARED_LIB = OFF, getting the .a static files (and not the .dll.a-files). Cmake did make a my_static_build\install\ directory, so the folders could change when setting another CMAKE_INSTALL_PREFIX.
Code:blocks: Using gcc and g++ as compiler; Changing Project -> Build options (not Settings -> Compiler, but probably doesn't matter):
2.1 Compiler settings -> Compiler Flags: Have g++ follow the C++11 ISO C++ language standard; Optimize fully (for speed)
2.2 Linker settings -> Link libraries: I added all .a files of the directories: C:\OpenCV\my_static_build\lib and C:\OpenCV\my_static_build\install\x86\mingw\staticlib. These are around 90 .a-files.
2.3 Linker settings -> Other linker options: -static -static-libstdc++
2.4 Search directories -> Compiler: C:\OpenCV\my_static_build\install\include
2.5 Search directories -> Linker: C:\OpenCV\my_static_build\lib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With