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

opencv undefined reference problem

asked 2013-03-05 09:16:21 -0500

AdrianPeng gravatar image

I am trying to build learning_image_transport from image_transport tutorial on Gumstix Overo which has ros groovy running on linaro.

However, one of dependencies of learning_image_transport -- opencv2 cannot be resolved in system dependency. So I cannot use rosdep to install opencv2.

Then I went to http://opencv.org/downloads.html and downloaded version 2.4.3 and followed instruction to install OpenCV.

Then I copy opencv and opencv2 from usr/local/include to /ros_core_ws/install/include so that ROS can find all the header file of OpenCV(such as highgui.h).

However, when I make learning_image_transport, I got the following error:

  [ 50%] Building CXX object CMakeFiles/my_publisher.dir/src/my_publisher.cpp.o
  In file included from /root/ros_core_ws/install/include/opencv2/flann/kmeans_index.h:50:0,
               from /root/ros_core_ws/install/include/opencv2/flann/all_indices.h:38,
               from /root/ros_core_ws/install/include/opencv2/flann/flann_base.hpp:44,
               from /root/ros_core_ws/install/include/opencv2/flann/flann.hpp:50,
               from /root/ros_core_ws/install/include/opencv/cv.h:69,
               from /root/catkin_ws/src/vision_opencv-fuerte-devel/cv_bridge/include/cv_bridge/CvBridge.h:41,
               from /root/catkin_ws/src/learning_image_transport/src/my_publisher.cpp:5:
  /root/ros_core_ws/install/include/opencv2/flann/logger.h:73:9: note: the mangling of ‘va_list’ has changed in GCC 4.4
  In file included from /root/catkin_ws/src/learning_image_transport/src/my_publisher.cpp:5:0:
  /root/catkin_ws/src/vision_opencv-fuerte-devel/cv_bridge/include/cv_bridge/CvBridge.h: In static member function ‘static sensor_msgs::Image_<std::allocator<void> >::Ptr sensor_msgs::CvBridge::cvToImgMsg(const IplImage*, std::string)’:
  /root/catkin_ws/src/vision_opencv-fuerte-devel/cv_bridge/include/cv_bridge/CvBridge.h:408:55: warning: ‘static bool sensor_msgs::CvBridge::fromIpltoRosImage(const IplImage*, sensor_msgs::Image&, std::string)’ is deprecated (declared at /root/catkin_ws/src/vision_opencv-fuerte-devel/cv_bridge/include/cv_bridge/CvBridge.h:307) [-Wdeprecated-declarations]
  /root/catkin_ws/src/learning_image_transport/src/my_publisher.cpp: In function ‘int main(int, char**)’:
  /root/catkin_ws/src/learning_image_transport/src/my_publisher.cpp:15:84: warning: ‘static sensor_msgs::Image_<std::allocator<void> >::Ptr sensor_msgs::CvBridge::cvToImgMsg(const IplImage*, std::string)’ is deprecated (declared at /root/catkin_ws/src/vision_opencv-fuerte-devel/cv_bridge/include/cv_bridge/CvBridge.h:405) [-Wdeprecated-declarations]
  Linking CXX executable ../bin/my_publisher
  CMakeFiles/my_publisher.dir/src/my_publisher.cpp.o: In function `cv::WImageBufferC<unsigned char, 3>::ReleaseImage()':
  /root/ros_core_ws/install/include/opencv2/core/wimage.hpp:399: undefined reference to `cvReleaseImage'
  /root/ros_core_ws/install/include/opencv2/core/wimage.hpp:399: undefined reference to `cvReleaseImage'
  CMakeFiles/my_publisher.dir/src/my_publisher.cpp.o: In function `sensor_msgs::CvBridge::fromIpltoRosImage(_IplImage const*, sensor_msgs::Image_<std::allocator<void> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
  /root/catkin_ws/src/vision_opencv-fuerte-devel/cv_bridge/include/cv_bridge/CvBridge.h:311: undefined reference to `cvGetMat'
  CMakeFiles/my_publisher.dir/src/my_publisher.cpp.o: In function `main':
  /root/catkin_ws/src/learning_image_transport/src/my_publisher.cpp:14: undefined reference to `cvLoadImage'

In wimage.hpp file, it includes opencv2/core/core_c.h which defines:

CVAPI(IplImage*)  cvCreateImage( CvSize size, int depth, int channels );
CVAPI(void)  cvReleaseImage( IplImage** image );
CVAPI(void*) cvLoad( const char* filename,
                 CvMemStorage* memstorage CV_DEFAULT(NULL),
                 const char* name CV_DEFAULT(NULL),
                 const char** real_name CV_DEFAULT(NULL) );

However, in opencv2/core/types_c.h which is included ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2014-05-16 23:43:22 -0500

Wolf gravatar image

Quote:

Then I copy opencv and opencv2 from usr/local/include to /ros_core_ws/install/include so that ROS can find all the header file of OpenCV(such as highgui.h).

Do not do that!

Add to your CMakeLists.txt:

find_package( OpenCV REQUIRED )

include_directories( ${OpenCV_INCLUDE_DIRS} )

and link your targets against OpenCV_LIBS:

target_link_libraries( your_target ${OpenCV_LIBS} )
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-05 09:16:21 -0500

Seen: 5,426 times

Last updated: May 16 '14