Ask Your Question

Error while linking OpenCV

asked 2013-05-05 22:33:21 -0500

roleiland gravatar image

updated 2014-01-31 13:47:30 -0500

tfoote gravatar image

Hello everyone, I am using ROS Fuerte and in the project that I use OpenCV with ROS I can compile perfectly. The problem is, if I try to compile a project normal project that uses OpenCV (out of ROS), I get errors while linking:

$ make g++ -Wall -DASSERT -O3 -g pkg-config opencv --cflags -o main.o -c main.cpp main.cpp: In function ‘int main(int, char**)’: main.cpp:44:5: warning: ‘key’ may be used uninitialized in this function [-Wuninitialized]

g++ pkg-config opencv --libs -o main main.o main.o: In function main': /home/roleiland/Desktop/video_test/main.cpp:29: undefined reference tocvCreateFileCapture' /home/roleiland/Desktop/video_test/main.cpp:39: undefined reference to cvGetCaptureProperty' /home/roleiland/Desktop/video_test/main.cpp:42: undefined reference tocvNamedWindow' /home/roleiland/Desktop/video_test/main.cpp:52: undefined reference to cvShowImage' /home/roleiland/Desktop/video_test/main.cpp:55: undefined reference tocvWaitKey' /home/roleiland/Desktop/video_test/main.cpp:46: undefined reference to cvQueryFrame' /home/roleiland/Desktop/video_test/main.cpp:59: undefined reference tocvReleaseCapture' /home/roleiland/Desktop/video_test/main.cpp:60: undefined reference to `cvDestroyWindow' collect2: ld returned 1 exit status make: * [main] Error 1

If I execute:

$ pkg-config opencv --libs

-L/opt/ros/fuerte/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab

$ ls /opt/ros/fuerte/lib/ libflann_cpp_s.a libflann_cpp_s-gd.a libflann_s.a ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-03-13 15:57:06 -0500

ahendrix gravatar image

I think this is linking order; the library flags for opencv should be specified after the .o files in the linking step:

g++ -o main main.o main.o `pkg-config opencv --libs`
edit flag offensive delete link more

answered 2016-03-13 15:05:28 -0500

Oded gravatar image

It seems that you don't include the header when you compile


Look at this answer

edit flag offensive delete link more


This is an error from the linker, and is clearly not an include path problem.

ahendrix gravatar image ahendrix  ( 2016-03-13 15:57:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-05 22:33:21 -0500

Seen: 1,001 times

Last updated: Mar 13 '16