ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

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/

libactionlib.so libopencv_flann.so libopencv_photo.so.2.4 libpcl_io_ply.so.1.5.1 libpcl_segmentation.so libcpp_common.so libopencv_flann.so.2.4 libopencv_photo.so.2.4.2 libpcl_io.so libpcl_segmentation.so.1.5 libflann_cpp-gd.so libopencv_flann.so.2.4.2 libopencv_stitching.so libpcl_io.so.1.5 libpcl_segmentation.so.1.5.1 libflann_cpp_s.a libopencv_gpu.so libopencv_stitching.so.2.4 libpcl_io.so.1.5.1 libpcl_surface.so libflann_cpp_s-gd.a libopencv_gpu.so.2.4 libopencv_stitching.so.2.4.2 libpcl_kdtree.so libpcl_surface.so.1.5 libflann_cpp.so libopencv_gpu.so.2.4.2 libopencv_ts.so libpcl_kdtree.so.1.5 libpcl_surface.so.1.5.1 libflann_cpp.so.1.7 libopencv_highgui.so libopencv_ts.so.2.4 libpcl_kdtree.so.1.5.1 libpcl_tracking.so libflann_cpp.so.1.7.1 libopencv_highgui.so.2.4 libopencv_ts.so.2.4.2 libpcl_keypoints.so libpcl_tracking.so.1.5 libflann_s.a libopencv_highgui.so.2.4.2 libopencv_video.so libpcl_keypoints.so.1.5 libpcl_tracking.so.1.5.1 libflann.so libopencv_imgproc.so libopencv_video.so.2.4 libpcl_keypoints.so.1.5.1 libpcl_visualization.so libflann.so.1.7 libopencv_imgproc.so.2.4 libopencv_video.so.2.4.2 libpcl_octree.so libpcl_visualization.so.1.5 libflann.so.1.7.1 libopencv_imgproc.so.2.4.2 libopencv_videostab.so libpcl_octree.so.1.5 libpcl_visualization.so.1.5.1 libmessage_filters.so libopencv_legacy.so libopencv_videostab.so.2.4 libpcl_octree.so.1.5.1 librosbag.so libopencv_calib3d.so libopencv_legacy.so.2.4 libopencv_videostab.so.2.4.2 libpcl_range_image_border_extractor.so librosconsole.so libopencv_calib3d.so.2.4 libopencv_legacy.so.2.4.2 libpcl_common.so libpcl_range_image_border_extractor.so.1.5 libroscpp_serialization.so libopencv_calib3d.so.2.4.2 libopencv_ml.so libpcl_common.so.1.5 libpcl_range_image_border_extractor.so.1.5.1 libroscpp.so ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

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
-1

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

Oded gravatar image

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

g++ ... -I/PATH/TO/HEADER/FILES

Look at this answer

edit flag offensive delete link more

Comments

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

Question Tools

Stats

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

Seen: 1,144 times

Last updated: Mar 13 '16