Jorge Vega Sánchez
Jorge Vega Sánchez

Reputation: 7590

OpenCV as a static library (cmake options)

I want to use OpenCV library in an embedded system and I need to compile my project using OpenCV as a static library.

How can I create the library using cmake options ?

Upvotes: 50

Views: 69253

Answers (2)

oarfish
oarfish

Reputation: 4641

The BUILD_SHARED_LIBS=OFF cmake option will create static libraries.

It should be noted that at the time of writing this, OpenCV does not really support static build, in that the result will not be useable when installed somewhere.

https://github.com/opencv/opencv/issues/21447#issuecomment-1013088996

Upvotes: 1

Andrey Kamaev
Andrey Kamaev

Reputation: 30152

To build OpenCV as static library you need to set BUILD_SHARED_LIBS flag to false/off:

cmake -DBUILD_SHARED_LIBS=OFF ..

But I think it is not enough for your task because you actually need to cross-compile library for you architecture. In case of Android or IOS such port already exists and you can simply use it. In case of another platform you need to create your own cmake toolchain file for cross-compiling and probably make a number of fixes in OpenCV build system.

Upvotes: 77

Related Questions