Linking errors when compiling code with OpenCV Libraries

元气小坏坏 提交于 2019-12-18 02:27:06

问题


I'm trying to compile a sample program after installing Opencv with the command:

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.

Was there anything I may have missed?


回答1:


You need to add another -L argument specifying the actual location of the OpenCV libraries.




回答2:


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.
For better handling with OpenCV programming go with an IDE like code::block.

Maybe this tutorial will help you in OpenCV programming with code::block:
How to Setup OpenCV for code :: block in Linux and Windows?




回答3:


Recently I started using OpenCV and I got similar problem and for me this works really well:

-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

Hope it will solve your problem.



来源:https://stackoverflow.com/questions/4559945/linking-errors-when-compiling-code-with-opencv-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!