[英]Linking errors when compiling code with OpenCV Libraries
I'm trying to compile a sample program after installing Opencv with the command: 我正在尝试使用以下命令安装Opencv后编译示例程序:
g++ hello-world.cpp -o hello-world -I /usr/local/include/opencv -L /usr/local/lib -lm -lcv -lhighgui -lcvaux
however, I'm getting an error that says: 但是,我收到的错误是:
/usr/bin/ld: cannot find -lcv
/usr/bin/ld: cannot find -lhighgui
/uer/bin/ld: cannot find -lcvaux
collect2: ld returned 1 exit status
What do I need to do to correct this?? 我需要做些什么来纠正这个? I installed opencv by downloading the latest stable version and using cmake to create the build files, then ran make install from the command line. 我通过下载最新的稳定版本并使用cmake创建构建文件来安装opencv,然后从命令行运行make install。
Was there anything I may have missed? 有什么我可能错过的吗?
UPDATED- 更新-
Better use this command: 更好地使用此命令:
g++ opencv.cpp -o opencv -L `pkg-config --cflags --libs opencv`
The pkg-config
command will locate the correct include and library for your source code. pkg-config
命令将为您的源代码找到正确的include和库。
For better handling with OpenCV programming go with an IDE like code::block
. 为了更好地使用OpenCV编程处理,请使用类似code::block
的IDE。
Maybe this tutorial will help you in OpenCV programming with code::block
: 也许本教程将帮助您使用code::block
进行OpenCV编程:
How to Setup OpenCV for code :: block in Linux and Windows? 如何在Linux和Windows中为code :: block设置OpenCV?
Recently I started using OpenCV and I got similar problem and for me this works really well: 最近我开始使用OpenCV,我遇到了类似的问题,对我来说这很有效:
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
Hope it will solve your problem. 希望它能解决你的问题。
您需要添加另一个-L
参数,指定OpenCV库的实际位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.