openCV程序编译错误“libopencv_core.so.2.4:无法打开共享对象文件:没有这样的文件或目录"在 Ubuntu 12.04 中

openCV program compile error quot;libopencv_core.so.2.4: cannot open shared object file: No such file or directoryquot; in ubuntu 12.04(openCV程序编译错误“libopencv_core.so.2.4:无法打开共享对象文件:没有这样的文件或目录在 Ubuntu 12.04 中)
本文介绍了openCV程序编译错误“libopencv_core.so.2.4:无法打开共享对象文件:没有这样的文件或目录"在 Ubuntu 12.04 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ubuntu 12.04 中编译并安装了 openCV 2.4.2.在 /usr/local/include 下我可以看到目录 /usr/local/opencv/usr/local/opencv2.

I compiled and installed openCV 2.4.2 in ubuntu 12.04. Under /usr/local/include I can see the directories /usr/local/opencv and /usr/local/opencv2.

这是我写的代码:

#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc,char **argv)
{
   Mat image;
   image = imread(argv[1],1);

   if(argc != 2 || !image.data)
   {
       cout << "No image data
";
       return -1;
   }

   namedWindow("Display Image",CV_WINDOW_AUTOSIZE);
   imshow("Display Image",image);
   waitKey(0);
   return 0;
}

我使用这个命令行编译它:

I compiled it using this command line:

g++ DisplayImage.cpp -o DisplayImage `pkg-config opencv --cflags --libs` 

没有编译时错误,但是当我尝试使用 /DisplayImage code.png 运行生成的二进制文件时,我收到以下错误消息:

There were no compile time errors, however when I try to run the resulting binary with /DisplayImage code.png I get the following error message:

./DisplayImage: error while loading shared libraries: libopencv_core.so.2.4: cannot open shared object file: No such file or directory

推荐答案

你没有把共享库放到加载器可以找到的位置.查看 /usr/local/opencv/usr/local/opencv2 文件夹,看看它们是否包含任何共享库(以 lib 并且通常以 .so 结尾).当你找到它们时,创建一个名为 /etc/ld.so.conf.d/opencv.conf 的文件,并将存储库的文件夹的路径写入其中,每行一个.

You haven't put the shared library in a location where the loader can find it. look inside the /usr/local/opencv and /usr/local/opencv2 folders and see if either of them contains any shared libraries (files beginning in lib and usually ending in .so). when you find them, create a file called /etc/ld.so.conf.d/opencv.conf and write to it the paths to the folders where the libraries are stored, one per line.

例如,如果库存储在 /usr/local/opencv/libopencv_core.so.2.4 下,那么我会将其写入我的 opencv.conf 文件:

for example, if the libraries were stored under /usr/local/opencv/libopencv_core.so.2.4 then I would write this to my opencv.conf file:

/usr/local/opencv/

然后运行

sudo ldconfig -v

如果找不到库,请尝试运行

If you can't find the libraries, try running

sudo updatedb && locate libopencv_core.so.2.4

在外壳中.如果您在编译 OpenCV 后重新启动,则无需运行 updatedb.

in a shell. You don't need to run updatedb if you've rebooted since compiling OpenCV.

参考资料:

关于 Linux 上的共享库:http://www.eyrie.org/~eagle/notes/rpath.html

About shared libraries on Linux: http://www.eyrie.org/~eagle/notes/rpath.html

关于添加 OpenCV 共享库:http://opencv.willowgarage.com/wiki/InstallGuide_Linux

About adding the OpenCV shared libraries: http://opencv.willowgarage.com/wiki/InstallGuide_Linux

这篇关于openCV程序编译错误“libopencv_core.so.2.4:无法打开共享对象文件:没有这样的文件或目录"在 Ubuntu 12.04 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Linker returns quot;relocation has an invalid symbol at symbol index...quot;(链接器返回“重定位在符号索引处具有无效符号...)
Ambiguous call with overloaded r-value reference function(带有重载 r 值引用函数的模棱两可的调用)
Compile c++14-code with g++(用 g++ 编译 c++14 代码)
gdb error not in executable format: File format not recognized(gdb 错误不是可执行格式:文件格式无法识别)
How to list exported functions in a shared lib on Ubuntu(如何在 Ubuntu 的共享库中列出导出的函数)
OpenGL shaders don#39;t compile(OpenGL 着色器无法编译)