Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell cmake I want my project to link libraries statically?

Tags:

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?

like image 991
agnul Avatar asked Sep 20 '10 21:09

agnul


People also ask

How static library is linked?

Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.


1 Answers

Actually this issue seems to have already been fixed in the OpenCVConfig.cmake that comes with OpenCV. All you have to do is define OpenCV_STATIC in your CMakeLists.txt. I.e.

set(OpenCV_STATIC ON) find_package(OpenCV REQUIRED) 
like image 145
bcook Avatar answered Sep 18 '22 18:09

bcook