不能够链接到的OpenCV共享库(Linux)的 [英] Not able to link to shared library of OpenCV (Linux)

查看:1125
本文介绍了不能够链接到的OpenCV共享库(Linux)的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写的线以下问题是解决了,但我米面临的一个新的相关问题。
与以往略有不同,我编译和链接样本OpenCV的code为:

  G ++ facedetect.cpp -o人脸检测-I /home/harsh/Downloads/OpenCV-2.0.0/include/opencv/ -L /家庭/刺耳/下载/ OpenCV的-2.0 0.0 / lib目录/ -lcv -lcxcore -lcvaux -lml -lhighgui

这是现在不给任何错误,但是当我使用运行可执行

  ./人脸检测

我得到这个错误:

  ./人脸检测:错误而载入共享库:libcv.so.2.0:无法打开共享对象文件:没有这样的文件或目录

当我做符号链接,使用:

  LN -s libcv.so libcv.so.2.0

然后,错误是:

  LN:无法创建符号链接libcv.so.2.0:文件已存在

不知道怎么去解决这个问题。

在此先感谢..

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

我试图创建将动态地.so文件链接,将一台机器,其中的OpenCV是的不可以上执​​行安装了OpenCV的示例程序的可执行文件的Linux,但.so文件将是Linux机器上present。

我已搜查这方面的许多职位,但仍是不成功的。

我编的OpenCV是这样的:

  CD的OpenCV-2.0.0 /
cmake的-DBUILD_SHARED_LIBS = ON。
使

然后所有的编译库中创建的OpenCV-2.0.0 / lib目录

然后,在samples / c目录,我这样做:

  G ++ facedetect.cpp -o人脸检测-I /home/harsh/Downloads/OpenCV-2.0.0/include/opencv/ -L /家庭/刺耳/下载/ OpenCV的-2.0 0.0 / lib目录/ -llibcv -llibcxcore -llibcvaux -llibml -llibhighgui

但是,错误是:

 的/ usr / bin中/劳工处:找不到-llibcv
在/ usr /斌/劳工处:找不到-llibcxcore
在/ usr /斌/劳工处:找不到-llibcvaux
在/ usr /斌/劳工处:找不到-llibml
在/ usr /斌/劳工处:找不到-llibhighgui
collect2:劳工处返回1退出状态


解决方案

使用 -lcv -lcxcore ,等等。

要链接到 libfoo.so ,该标志为 -lfoo ,没有 LIB 部分。

如果您的库不在默认的运行时库搜索路径(这是怎么设置/管理取决于您的操作系统和分发上),则需要通知动态链接程序为它们所在的位置。 (就像你加入这样做,当你编译 -L 标记。)

在Linux上,这是通过设置环境变量 LD_LIBRARY_PATH 完成的,例如:

 导出LD_LIBRARY_PATH = /家庭/刺耳/下载/ OpenCV的-2.0.0 / lib中/:$ LD_LIBRARY_PATH
./your_app

The problem written below the line is solved but i m facing a new related problem. Slightly different from before, I am compiling and linking the sample OpenCV code as:

g++ facedetect.cpp -o facedetection -I /home/harsh/Downloads/OpenCV-2.0.0/include/opencv/ -L/home/harsh/Downloads/OpenCV-2.0.0/lib/ -lcv -lcxcore -lcvaux -lml -lhighgui

That doesn't give any errors now, but when I run the executable using

./facedetection

i get this error:

./facedetection: error while loading shared libraries: libcv.so.2.0: cannot open shared object file: No such file or directory

And when I do symbolic linking, using:

ln -s libcv.so libcv.so.2.0

Then the error is:

ln: failed to create symbolic link 'libcv.so.2.0': File exists

Don't know how to get around this.

Thanks in advance..

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

I am trying to create a linux executable of a sample OpenCV program that will be linked dynamically with .so files and will be executed on a machine where OpenCV is not installed, but the .so files will be present on that linux machine.

I have searched many posts regarding this but still am unsuccessful.

I compiled opencv like this:

cd OpenCV-2.0.0/
cmake -DBUILD_SHARED_LIBS=ON .
make

Then all the compiled libraries were created in OpenCV-2.0.0/lib

Then, in the samples/c directory, I did this:

g++ facedetect.cpp -o facedetection -I /home/harsh/Downloads/OpenCV-2.0.0/include/opencv/ -L/home/harsh/Downloads/OpenCV-2.0.0/lib/ -llibcv -llibcxcore -llibcvaux -llibml -llibhighgui

But Errors are :

/usr/bin/ld: cannot find -llibcv
/usr/bin/ld: cannot find -llibcxcore
/usr/bin/ld: cannot find -llibcvaux
/usr/bin/ld: cannot find -llibml
/usr/bin/ld: cannot find -llibhighgui
collect2: ld returned 1 exit status

解决方案

Use -lcv, -lcxcore, etc.

To link to libfoo.so, the flag is -lfoo, without the lib part.

If your libraries aren't in the default runtime library search path (how this is set/managed depends on your OS and distribution), you need to inform the dynamic linker as to where they are located. (Just like you have to do so when you compile by adding -L flags.)

On Linux, this is done by setting the environment variable LD_LIBRARY_PATH, e.g.:

export LD_LIBRARY_PATH=/home/harsh/Downloads/OpenCV-2.0.0/lib/:$LD_LIBRARY_PATH
./your_app

这篇关于不能够链接到的OpenCV共享库(Linux)的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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