I'm trying to build an OpenCV-based project using CMake, running on Linux. So far my CMakeLists.txt
files looks something like
FIND_PACKAGE (OpenCV REQUIRED)
...
TARGET_LINK_LIBRARIES (my-executable ${OpenCV_LIBS})
but this results in dynamically linked libraries. How do I link with static libraries?
Update: The default build for OpenCV builds only dynamic libraries, and of course trying to link those statically will fail. If I build static OpenCV libraries the only option seems to be manually adding the full paths to the libraries in the TARGET_LINK_LIBRARIES
command
Solved, sort of: Building a static OpenCV and listing all the libraries in the TARGET_LINK_LIBRARIES
command works, but it looks like I have to explicitly specify dependencies on things like librt
and libpthread
. I suspect the OpenCV_LIBS
macro took care of those as well.
... and another thing: the OpenCV_LIBS
macro works fine even with static libraries, so all I needed to do was just pointing CMake at a static OpenCV build.