如何编译独立的OpenCV可执行文件?(How to compile a standalone OpenCV executable?)

编程入门 行业动态 更新时间:2024-10-20 04:05:19
如何编译独立的OpenCV可执行文件?(How to compile a standalone OpenCV executable?)

我按如下方式编译我的OpenCV程序:

g++ `pkg-config --cflags opencv --libs opencv` <filename>.cpp

它在我的电脑上完美运行。 我可以单独使用该程序编译共享库,以便它可以在其他没有opencv的计算机上运行吗? 如果是这样,我该怎么办?

I compile my my OpenCV programs as follows:

g++ `pkg-config --cflags opencv --libs opencv` <filename>.cpp

It works perfectly on my computer. Can I complile the shared libraries alone with the program so that it can be run on other computers which doesnt have opencv on it? If so, how do I do it?

最满意答案

编译期间的程序动态链接到我们计算机上的共享库(.so文件)。 编译的可执行文件在运行时使用这些共享库。 但是这些共享库可能不存在于其他计算机上,因此可能无法运行可执行文件。

解决方案是静态链接存档库(.a文件)而不是动态链接共享库。 OpenCV不会像这样分发归档库。 因此,必须使用cmake -DBUILD_SHARED_LIBS=OFF从其源代码编译归档库。 此归档库可用于创建独立可执行文件。

The program during compilation are dynamically linked to Shared Libraries (.so files) on our computer. The executable compiled use these shared libraries during run-time. But these shared libraries may not be present on other computers, hence might not be able to run the executable.

Solution to this will be to statically link Archive Libraries (.a files) instead of dynamically linking Shared Libraries. OpenCV does not distribute archive libraries as such. So one will have to compile archive library from the its source using cmake -DBUILD_SHARED_LIBS=OFF. This archive library can be used to create standalone executable.

更多推荐

本文发布于:2023-07-31 00:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可执行文件   独立   OpenCV   executable   compile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!