Compiling and static linking / DLLs too small

57 views
Skip to first unread message

Claudius Coenen

unread,
Feb 10, 2015, 3:59:53 AM2/10/15
to psm...@googlegroups.com
Platform: Windows 7 / 64bit / MinGW64 4.9.2 posix sjlj for x86 and for x86_64

I am compiling the current master (f0bd675c42 from 2014-12-17) successfully, and i get two DLLs. I can run all of the tools _after_ i copy 6 dlls[1] from mingw and opencv into that same directory.

My DLLs are 170 and 100KB in size. Which is why probably, why i have to do the copying in the first place. I have noticed that the psmoveapi_tracker.dll in the provided builds of 3.0.0 is much larger than mine. My guess would be static linking of the external libs.

I experimented with PSMOVE_USE_LOCAL_OPENCV=ON for cmake, providing it with a OpenCV_DIR, but I had to modify the CMakeLists.txt to make that work. And i also had to copy over the headers from opencv into psmoveapi. Still, my build results are in the 100/170 KB range.

I'm clearly missing something, but i can't quite figure out, what?


[1] the 6 DLLs in question are:
opencv_imgproc, opencv_highgui, opencv_core
libwinpthread-1,libstdc++-6, libgcc_s_sjlj-1

Chadwick Boulay

unread,
Feb 10, 2015, 8:57:53 AM2/10/15
to psm...@googlegroups.com

I experimented with PSMOVE_USE_LOCAL_OPENCV=ON for cmake, providing it with a OpenCV_DIR, but I had to modify the CMakeLists.txt to make that work. And i also had to copy over the headers from opencv into psmoveapi. Still, my build results are in the 100/170 KB range.

Did you build OpenCV yourself? If so, did you tell cmake to -DBUILD_SHARED_LIBS=OFF? If you didn't do either of those things then your OpenCV libraries are shared objects and can only be linked dynamically. That's why they have the extension .dll (equivalent to .dylib on mac or .so on linux) instead of .lib (equivalent to .a in linux/mac/MinGW).

I've been building OpenCV myself without too much trouble, though I typically have to turn off some of its features, and I turn off others to save compile time. Here is my cmake line:
cmake .. -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=0 -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_flann=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF

If you are using OpenCV > 2.4.4 then the directories it outputs the libraries to have changed and you have to update psmoveapi's CMakeLists.txt to point to the new directory when using PSMOVE_USE_LOCAL_OPENCV

Claudius Coenen

unread,
Feb 10, 2015, 4:20:44 PM2/10/15
to psm...@googlegroups.com
You, Sir, just made my Day!

Am Dienstag, 10. Februar 2015 14:57:53 UTC+1 schrieb Chadwick Boulay:
[...] Still, my build results are in the 100/170 KB range.
Did you build OpenCV yourself? If so, did you tell cmake to -DBUILD_SHARED_LIBS=OFF?

I built it myself from the 2.4.9.1 tag from their git-repo, but i did not specify that flag. I just did a cmake .. -G "MinGW Makefiles" I will try that! Thanks!
 
I've been building OpenCV myself without too much trouble, though I typically have to turn off some of its features, and I turn off others to save compile time. Here is my cmake line:
cmake .. -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=0 -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_flann=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF

That helps me tremendously! You just saved me ~20 minutes just on compiling alone right there! Cheers!
 
 If you are using OpenCV > 2.4.4 then the directories it outputs the libraries to have changed and you have to update psmoveapi's CMakeLists.txt to point to the new directory when using PSMOVE_USE_LOCAL_OPENCV

Thanks for the notice, i think i will make those changes into a tiny pull request when i'm done. Would you mind if i included your opencv build flags in the readme?

(added later) i just built myself a huge libpsmoveapi_tracker.dll - thanks!

Alexander Nitsch

unread,
Feb 10, 2015, 6:17:38 PM2/10/15
to psm...@googlegroups.com
It seems I am a little bittle late to the party and you were already
pointed to BUILD_SHARED_LIBS in the OpenCV build setup. But I want to
add something.


> I am compiling the current master (f0bd675c42 from 2014-12-17)
> successfully, and i get two DLLs. I can run all of the tools _after_ i copy
> 6 dlls[1] from mingw and opencv into that same directory.
>
> My DLLs are 170 and 100KB in size. Which is why probably, why i have to do
> the copying in the first place. I have noticed that the
> psmoveapi_tracker.dll in the provided builds of 3.0.0 is much larger than
> mine. My guess would be static linking of the external libs.

Correct, the libs were linked statically in these builds.

But it is not required to statically link OpenCV. The reason why you had
to copy the DLLs was most likely a missing entry in the PATH environment
variable. The DLLs were simply not found. Copying them into the
executable's dir works because this is a default path to search for them.

So, instead of statically linking you could also add the directory
containing the OpenCV DLLs to your PATH variable and this should work.


Alex

Claudius Coenen

unread,
Feb 10, 2015, 6:36:34 PM2/10/15
to psm...@googlegroups.com, nit...@ht.tu-berlin.de
Am Mittwoch, 11. Februar 2015 00:17:38 UTC+1 schrieb Alexander Nitsch:
So, instead of statically linking you could also add the directory
containing the OpenCV DLLs to your PATH variable and this should work.

Usually, i'd prefer that, too. I am currently working on updating unimove with the latest improvements from psmoveapi. In that setup, static linking is, i think, preferable. At least until I find a way to add DLLs to Unity's build process in another way.
Reply all
Reply to author
Forward
0 new messages