Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

c++ - Linking errors when compiling code with OpenCV Libraries

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...