我按如下方式编译我的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>.cppIt 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.
更多推荐
发布评论