Rosanswers logo

Maybe it is brand new but I've recently noticed I can install ros-indigo-opencv3. It installs into the /opt/ros/indigo. There is also a opencv 2.4.8 already installed into the system outside of /opt in /usr/lib/x86_64-linux-gnu/, and every ros package from the repositories linked against opencv is linked to that.

When I try to build a package that depends on cv_bridge it fails:

CMakeFiles/rotate_cam.dir/src/rotate_cam.cpp.o: In function `RotateImage::RotateImage()':
rotate_cam.cpp:(.text+0x6dc): undefined reference to `cv::imread(cv::String const&, int)'
CMakeFiles/rotate_cam.dir/src/rotate_cam.cpp.o: In function `cv::String::~String()':
rotate_cam.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/rotate_cam.dir/src/rotate_cam.cpp.o: In function `cv::String::String(std::string const&)':
rotate_cam.cpp:(.text._ZN2cv6StringC2ERKSs[_ZN2cv6StringC5ERKSs]+0x69): undefined reference to `cv::String::allocate(unsigned long)'

And if I remove ros-indigo-opencv3 it builds fine. With VERBOSE=1 I don't see any trace of opencv3 includes or libraries (cv_bridge properly brings in 2.4.8 libraries, and includes /usr/include/opencv which is still 2.4.8).

The problem is that it is using opencv 3.0 headers and linking against 2.4.8, and breakage between those produces the link error.

When the a node dependent on opencv 2.4.8 builds it runs:

c++ ... -I/opt/ros/jade/include -I/usr/include/opencv ...

It seem like one problem is that opencv 3.0 is installed in the jade directories and 2.4.8 is in the usr directory- so it is using the wrong header files. But even when I correct this ordering the linker error still occurs.

What I'd like is to have opencv 3.0 available for special packages that need it (though they can't also link to cv_bridge, no mixing of 2.4.8 and 3.0 in the same package?).

I'm going to try to duplicate this problem on a small scale, it is possibly an artifact of something in one of my cmake files in my large workspace.

Ubuntu 14.04.2

Originally posted by lucasw on ROS Answers with karma: 8729 on 2015-07-18

Post score: 8

Original comments

Comment by jeremya on 2015-09-28:
Any update on this? I working on a project with similar concerns.

Comment by lucasw on 2015-11-30:
Tried this with ros-jade-opencv3.0 and it fails the same way.

Comment by lucasw on 2015-11-30:
See https://github.com/ros-perception/vision_opencv/issues/79

Comment by lucasw on 2015-11-30:
@jeremya I was able to get opencv 3.0 installed from source to a non-standard location and have a specific package find_package it. ros-indigo-opencv3 seems just plain broken. http://answers.ros.org/question/213925/opencv30-ros-indigo/?answer=213928#post-id-213928


1 Answer 1


Rosanswers logo

My current solution is to build OpenCV 3.0 from source and then install it into a location that is not on any paths. Then in the package

# don't use opencv as found by any prior running of find_package
unset(OpenCV_DIR CACHE)

set(CMAKE_PREFIX_PATH "$ENV{HOME}/special/install")
find_package(OpenCV 3.0 REQUIRED)

# restore CMAKE_PREFIX_PATH and other cached variables
# so nothing other package finds this opencv

unset(OpenCV_DIR CACHE)




Originally posted by lucasw with karma: 8729 on 2015-12-01

This answer was ACCEPTED on the original site

Post score: 5

Original comments

Comment by Thomas D on 2015-12-31:
With this solution do you still have the limitation that you can't use cv_bridge in the same node?

Comment by lucasw on 2016-01-19:
It does have that limitation- I haven't done it but cv_bridge could maybe be recompiled against cv 3.0 in the workspace.

Comment by cyberguy42 on 2016-02-23:
I spent hours trying to do this before finding this answer! I can confirm that cv_bridge can be used in the same node: recompile cv_bridge from source and use this approach for both your code and cv_bridge.

Comment by jtim on 2016-07-27:
@Cyberguy42 did you do something special to compile from source, because dpkg did not help me.

Comment by cyberguy42 on 2016-07-28:
I didn't use dpkg at all; I downloaded this package link text to my catkin workspace, applied the suggested changes to each affected CMakeLists, and compiled.

Comment by cyberguy42 on 2016-07-28:
However, I did encounter issues making my program into a nodelet: it compiled fine, but crashed at run time. Debugging revealed that it was trying to call the 2.4.8 library. Static compiling of 3.0 into my program didn't fix the problem. Lesson: run 2.4.8 and 3.0 code in separate processes.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.