如何编译一个独立的OpenCV可执行文件? [英] How to compile a standalone OpenCV executable?

查看:239
本文介绍了如何编译一个独立的OpenCV可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译我的OpenCV程序如下:

I compile my my OpenCV programs as follows:

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

我可以编译共享库单独的程序,以便它可以在没有opencv的其他计算机上运行吗?

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文件)我们的电脑。可执行文件在运行时使用这些共享库。但是这些共享库可能不存在于其他计算机上,因此可能无法运行可执行文件。

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.

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

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.

这篇关于如何编译一个独立的OpenCV可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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