Problem with static built
Hi guys,
for me personally, the "NOT DEFINED BUILD_SHARED_LIBS" in line 46 of OpenCVConfig.cmake:
if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
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
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?
^^ cmake seems to generate this for your own opencv projects.
if you don't have
BUILD_SHARED_LIBS=OFF
defined (how can that be ?) you will have to setOpenCV_STATIC=ON
manually.i think, it's from here
@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.
the 1st comment was for steven, who probably misread, what you're doing. (that it's not the user, but cmake generating these lines)
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: 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.
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).