Problem with static built

asked 2018-08-30 02:57:55 -0500

DrPepperJo gravatar image

updated 2018-09-01 12:20:10 -0500

Hi guys,

for me personally, the "NOT DEFINED BUILD_SHARED_LIBS" in line 46 of OpenCVConfig.cmake:


results in OpenCV_STATIC to be set to OFF, even if OpenCV was actually compiled statically. Am I doing something wrong or is this a bug?

Cheers, Jo

edit retag flag offensive close merge delete


You either go for shared libs, aka dynamically, or go for a static build. Both are just contradictions. Why would you like to combine them?

StevenPuttemans gravatar imageStevenPuttemans ( 2018-08-30 06:50:21 -0500 )edit

^^ cmake seems to generate this for your own opencv projects.

berak gravatar imageberak ( 2018-08-30 08:00:19 -0500 )edit

if you don't have BUILD_SHARED_LIBS=OFF defined (how can that be ?) you will have to set OpenCV_STATIC=ON manually.

i think, it's from here

berak gravatar imageberak ( 2018-09-03 05:07:14 -0500 )edit

@StevenPuttemans: I do not understand exactly what you are trying to say. But in general it is totally ok to link static libs into dlls or exes.

@berak: I do not understand your first comment. I've been using this for some time now. Setting OpenCV_STATIC=ON definitely solves the problem. This whole issue is a little confusing for me, I don't get how BUILD_SHARED_LIBS in my program has anything to do with the OpenCV library I'm linking in. Of course it would make sense to manuelly define OpenCV_STATIC, if the OpenCV folder contains both static and dynamic binaries. Otherwise, it should be static vs dynamic should be a property of the CMake generated during building / installation. As this "NOT DEFINED" part seems to be new, this has never been an issue in the past.

DrPepperJo gravatar imageDrPepperJo ( 2018-09-03 07:47:44 -0500 )edit

the 1st comment was for steven, who probably misread, what you're doing. (that it's not the user, but cmake generating these lines)

I don't get how BUILD_SHARED_LIBS in my program has anything to do with the OpenCV library I'm linking in.

static linking IS somewhat different. the order of the libs matters, and also it needs to add all those system libs, that were conveniently linked into the so/dll's before (think of libpng, zlib, etc)

berak gravatar imageberak ( 2018-09-03 07:52:43 -0500 )edit

@berak: So what you are saying is that by specifying OpenCV_STATIC manually in your project, you are stating to OpenCV that you know what you are doing :)? I'd suggest that it's probably rather a matter of putting both shared and static libs in one installation and then deciding in your CMake files what to do (like you can with Boost e.g.). Until now, I always thought that one would compile and install OpenCV only either shared or static and than the respective files are used.

DrPepperJo gravatar imageDrPepperJo ( 2018-09-04 04:00:03 -0500 )edit

i think, normally, it should have saved the state of BUILD_SHARED_LIBS somewhere.

and the OpenCV_STATIC is more a hint to cmake , that it also has to link all the dependancies to your prog now (which in the dynamic case are already linked to the dlls before).

berak gravatar imageberak ( 2018-09-04 04:24:32 -0500 )edit