问题
I compiled OpenCV 3.x with the Static Libraries options (-DBUILD_SHARED_LIBS=OFF
).
No I have a project built with few functions which uses OpenCV.
I want to build my project as a portable static library.
By portable I mean I can share it with others to use my functions in their code without the need to install OpenCV.
How can I do that on Windows, macOS and Linux?
I would like the process to be done using a Compiler in order to extract only the needed objects (Functions) from all OpenCV libraries.
How is it different from other questions on the subject?
The difference in my question versus the generic answer of archiving multiple static libraries into one is the selection of which functions to include.
Let's say we have 2 static libraries - lib001.lib
and lib002.lib
.
Where lib001.lib
has the functions fun001()
, fun002()
and fun003()
and lib002.lib
has fun004()
, fun005()
and fun006()
.
Let's assume the functions has dependency which I'm not aware of (I didn't write the libraries). So in my project I use fun001()
and fun005()
and let's say fun001()
depends on fun004()
and fun005()
depends on fun002()
.
What I'd like is the linker to understand this and build me a custom static library which includes my functions and fun001()
, fun002()
fun003()
and fun004()
without me telling the dependency.
Remark
Above I assume each object in the static library is a function. One could replace the use of functions by objects to be more accurate.
回答1:
If you wish to compile OpenCV on a static manner on all the 3 platforms you mentioned, I would suggest to use conan.io package manager (here is the conan-opencv package), by issuing the command:
conan install opencv/4.1.1@conan/stable -o shared=False --build=missing
And from there, using conan in your project and make a final static executable.
Here is the official documentation of Conan, complete with examples.
In your case, your conanfile.txt will have the follow content:
[requires]
opencv/4.1.1@conan/stable
[generators]
cmake
[options]
opencv:shared=False
来源:https://stackoverflow.com/questions/57939317/create-a-portable-static-library-from-a-project-based-on-opencv-static-libraries