Ask Your Question

Problem when compiling OpenCV with ROS

asked 2015-03-21 02:16:17 -0500

RuiH gravatar image

I am using rosbuild to build a project with OpenCV and ROS. The OpenCV version is 2.4.9, built and installed from source. The ROS version is indigo.

When I include the nonfree module of OpenCV (has SIFT and SURF) in my project files, I got a linking error something like" undefined reference to ocl::integral()" after I build the ROS package using the CMakeList.txt.

I noticed that the compilation information in the terminal shows the compiler is also trying to link to some existing OpenCV 2.4.8 libs in the directory /lib/x86_64-linux-gnu/libgopencv*.so.2.4.8.

I realized that the OpenCV 2.4.8 might come with the CV_Bridge package when I install it. It seems the cmake is trying to link to some libs of 2.4.8 and also 2.4.9, which leads to some undefined reference. Another observation is that without ROS, I am able to compile a project with OpenCV (using pkg-config).

It seems the problem is the co-existence of two versions of OpenCV. How can I make it only link to the version I choose? I used find_package in the CMakeList file, but the compiler always tries to link to both version.

Thanks you very much. Rui

edit retag flag offensive close merge delete


Just to make sure: are you really using rosbuild or catkin?

gvdhoorn gravatar image gvdhoorn  ( 2015-03-21 04:12:37 -0500 )edit

I am using rosbuild.

RuiH gravatar image RuiH  ( 2015-03-21 16:30:36 -0500 )edit

Hi, I have the same problem when I use the nonfree module in ROS Indigo, have you found a solution for this error?

Dinl gravatar image Dinl  ( 2015-08-31 18:22:35 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2016-05-22 21:00:32 -0500

willSapgreen gravatar image

My system info:

  • Ubuntu 14.04.3 LTS
  • OpenCV 2.4.13
  • ROS Jade

I have the same link error but fix by switching the following content in CMakeLists.txt

  • ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} in target_link_libraries
  • ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} in include_directories

OpenCV first, then catkin.

Hopefully this approach can resolve your problem.

edit flag offensive delete link more


I had the same problem, these procedure solve it! Thanks

michalszczepanski gravatar image michalszczepanski  ( 2017-04-14 04:32:20 -0500 )edit

answered 2015-03-23 08:32:36 -0500

Wolf gravatar image

To make ROS surely building against your own version and not the version that comes with ROS you can use in your ROS-package's CMakeLists.txt

  find_package( OpenCV 2.4.9 EXACT REQUIRED )

2.4.9 is than your manually compiled version, which must then differ from the version that comes with ROS

edit flag offensive delete link more

answered 2015-08-31 19:59:23 -0500

Dinl gravatar image

updated 2015-09-01 02:09:05 -0500

gvdhoorn gravatar image

I had this error, this is the way that I found to solve it, apparently the problem is with OpenCL that is compiled by default with OpenCV, so you have to uninstall OpenCV and install again using the .sh file and modify the cmake line:



edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2015-03-21 02:16:17 -0500

Seen: 2,214 times

Last updated: May 22 '16