从基于OpenCV静态库的项目创建可移植静态库 [英] Create a Portable Static Library from a Project Based on OpenCV Static Libraries

查看:226
本文介绍了从基于OpenCV静态库的项目创建可移植静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用静态库"选项(-DBUILD_SHARED_LIBS=OFF)编译了OpenCV 3.x.

I compiled OpenCV 3.x with the Static Libraries options (-DBUILD_SHARED_LIBS=OFF).

否,我有一个使用少量功能使用OpenCV构建的项目.
我想将我的项目构建为可移植的静态库.
用可移植的意思是我可以与其他人共享它,而无需安装OpenCV就可以在我的代码中使用我的功能.

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.

如何在Windows,macOS和Linux上执行此操作?
我希望使用编译器来完成该过程,以便仅从所有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.

假设我们有2个静态库-lib001.liblib002.lib.
其中lib001.lib具有功能fun001()fun002()fun003(),而lib002.lib具有功能fun004()fun005()fun006().

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().

让我们假设函数具有我不知道的依赖关系(我没有编写库).因此,在我的项目中,我使用fun001()fun005(),假设fun001()依赖于fun004(),而fun005()依赖于fun002().

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().

我想要的链接器是为了理解这一点并为我构建一个自定义的静态库,其中包括我的函数以及fun001()fun002() fun003()fun004(),而无需告诉我依赖关系.

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.

推荐答案

如果您希望在提到的所有3个平台上以静态方式编译OpenCV,我建议使用conan.io软件包管理器(这是conan-opencv软件包).

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

然后从那里开始,在项目中使用conan并生成最终的静态可执行文件.

And from there, using conan in your project and make a final static executable.

此处是柯南的官方文档,并附带示例.

Here is the official documentation of Conan, complete with examples.

在您的情况下,您的conanfile.txt将具有以下内容:

In your case, your conanfile.txt will have the follow content:

[requires]
opencv/4.1.1@conan/stable

[generators]
cmake

[options]
opencv:shared=False

这篇关于从基于OpenCV静态库的项目创建可移植静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆