关于libs,pkg-config和opencv的基本构建问题 [英] Basic build issue regarding libs, pkg-config and opencv

查看:124
本文介绍了关于libs,pkg-config和opencv的基本构建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功构建并安装了opencv库。现在我正在尝试在我的应用程序中使用这些库,但我一直在收到链接错误。我正在使用:

  pkg-config --libs opencv 

当我在命令行上运行它时,我可以看到输出。它列出了很多库,但并不是所有库都以指定的绝对路径列出。例如,以下是部分输出:

  libippcc_l.a libippvm_l.a tbb rt pthread m dl / usr / lib / libXext .s stdc ++ 

当我构建我的应用程序时,出现链接错误。这是一个部分输出:

  g ++:libipps_l.a:没有这样的文件或目录
g ++:libippi_l.a :没有这样的文件或目录
g ++:libippcv_l.a:没有这样的文件或目录
g ++:libippcc_l.a:没有这样的文件或目录
g ++:libippvm_l.a:没有这样的文件或目录
g ++:tbb:没有这样的文件或目录
g ++:rt:没有这样的文件或目录
g ++:pthread:没有这样的文件或目录
g ++:m:没有这样的文件或目录文件或目录
g ++:dl:没有这样的文件或目录
g ++:stdc ++:没有这样的文件或目录

看起来链接器无法解析那些不包含绝对路径的库,这似乎是合理的。但是我的困惑是,为什么不从pkg-config的输出中包含所有库的绝对路径?当我不在生成线上使用pkg-config --libs opencv时,intel ipp,pthread,m,stdc ++等库会得到正确解析,并且应用程序生成良好,因为我也在链接行上指定了它们例如:-lpthread -lstdc ++...等等。这些位于链接行之后,我指定:pkg --libs opencv



但是使用 pkg-config --libs opencv搞定了分辨率。

我已经从命令行运行ldconfig来更新我的libs目录中的所有符号链接,但是这并没有解决这个问题。



任何帮助将不胜感激。

解决方案

如果 pkg-config --libs opencv 正在输出,那么你有问题。也许之前的OpenCV安装破坏了它,或者你刚刚没有使用足够版本的版本,或者它没有被成功编译,或者从版本库的最新版本出现问题。



无论如何,我在Mac OS X上使用OpenCV 2.3.1并且 pkg-config --libs opencv 输出以下信息:

  -L / usr / local / lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy  - lopencv_flann 

您可以尝试手动编译您的应用程序以查看是否有其他内容被破坏:

  g ++ test.cpp -o test -I / usr / local / include / opencv -I / usr / local / include -L / usr / local / lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann 



请注意,您的安装可能会将OpenCV标头和库放置在不同的目录中。


I have successfully built and installed the opencv lib. Now I am trying to use these libs in my application but I keep getting link errors. I am using:

pkg-config --libs opencv

When I run this on the command line I can see the output. It list a lot of libraries but not all of them are listed with the absolute path specified. For example, here is a partial output:

libippcc_l.a libippvm_l.a tbb rt pthread m dl /usr/lib/libXext.s stdc++

And when I build my app I get link errors. Here is a partial output:

g++: libipps_l.a: No such file or directory
g++: libippi_l.a: No such file or directory
g++: libippcv_l.a: No such file or directory
g++: libippcc_l.a: No such file or directory
g++: libippvm_l.a: No such file or directory
g++: tbb: No such file or directory
g++: rt: No such file or directory
g++: pthread: No such file or directory
g++: m: No such file or directory
g++: dl: No such file or directory
g++: stdc++: No such file or directory

It appears that the linker cannot resolve the libraries that do not include an absolute path which seems reasonable. But my confusion is why dosn't the output from pkg-config include the absolute path for all of its libs? When I do NOT use "pkg-config --libs opencv" on the build line, the libraries for intel ipp, pthread, m, stdc++, etc gets resolved properly and the app builds fine because I also have them specified on the link line as: "-lpthread -lstdc++" ... etc. These are positioned on the link line AFTER the I specify: "pkg --libs opencv"

But using "pkg-config --libs opencv" screws up the resolution.

I have run "ldconfig" from the command line to update all of the symbolic links in my libs directories but this did not resolve this problem.

Any help would be greatly appreciated.

解决方案

If pkg-config --libs opencv is outputting that, then you have a problem. Maybe a previous installation of OpenCV broke it, or maybe you are not using a version recent enough, or maybe it wasn't compiled successfully, or maybe there's a problem with the newest version from the repository.

Anyway, I'm using OpenCV 2.3.1 on Mac OS X and pkg-config --libs opencv outputs the following info:

-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann 

You can try to compile your application by hand to see if anything else is broken:

g++ test.cpp -o test -I/usr/local/include/opencv -I/usr/local/include  -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

Note that your install might have placed OpenCV headers and libraries in different directories.

这篇关于关于libs,pkg-config和opencv的基本构建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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