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

catkin_make not linking opencv dependencies

asked 2016-01-26 10:01:38 -0600

zqpm gravatar image

updated 2016-01-26 12:57:26 -0600

gvdhoorn gravatar image

Something has gotten screwed up on one of my machines and now catkin_make is not linking opencv dependencies correctly (or something along those lines), i.e., I'm am getting a long list of errors of the format: In function 'SOME OPENCV FUNCTION', undefined reference to 'X'.

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(gl_core_3_1.cpp.o): In function `IntGetProcAddress(char const*)':
(.text._ZL17IntGetProcAddressPKc+0x15): undefined reference to `glXGetProcAddressARB'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::makeKey()':
(.text._ZN2cvL7makeKeyEv+0x14): undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::Mutex::Mutex()':
(.text._ZN2cv5MutexC2Ev+0x1c): undefined reference to `pthread_spin_init'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::Mutex::~Mutex()':
(.text._ZN2cv5MutexD2Ev+0x34): undefined reference to `pthread_spin_destroy'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::Mutex::operator=(cv::Mutex const&)':
(.text._ZN2cv5MutexaSERKS0_+0x41): undefined reference to `pthread_spin_destroy'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::Mutex::lock()':
(.text._ZN2cv5Mutex4lockEv+0x4): undefined reference to `pthread_spin_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::Mutex::unlock()':
(.text._ZN2cv5Mutex6unlockEv+0x4): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::Mutex::trylock()':
(.text._ZN2cv5Mutex7trylockEv+0x8): undefined reference to `pthread_spin_trylock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::~TLSDataContainer()':
(.text._ZN2cv16TLSDataContainerD2Ev+0x1f): undefined reference to `pthread_spin_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::~TLSDataContainer()':
(.text._ZN2cv16TLSDataContainerD2Ev+0x42): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::~TLSDataContainer()':
(.text._ZN2cv16TLSDataContainerD2Ev+0x10f): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSStorage::~TLSStorage()':
(.text._ZN2cv10TLSStorageD2Ev+0x3d): undefined reference to `pthread_spin_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSStorage::~TLSStorage()':
(.text._ZN2cv10TLSStorageD2Ev+0x62): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSStorage::~TLSStorage()':
(.text._ZN2cv10TLSStorageD2Ev+0xcd): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::TLSDataContainer()':
(.text._ZN2cv16TLSDataContainerC2Ev+0x24): undefined reference to `pthread_spin_lock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::TLSDataContainer()':
(.text._ZN2cv16TLSDataContainerC2Ev+0x6d): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::TLSDataContainer()':
(.text._ZN2cv16TLSDataContainerC2Ev+0xab): undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::getData() const':
(.text._ZNK2cv16TLSDataContainer7getDataEv+0x22): undefined reference to `pthread_once'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libopencv_core.a(system.cpp.o): In function `cv::TLSDataContainer::getData() const ...
(more)
edit retag flag offensive close merge delete

Comments

Please format console copy/pastes using the Preformatted text button on the formatting toolbar (the one with 101010 on it). It makes things much easier to read. Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2016-01-26 11:26:07 -0600 )edit

Okay. Hope that's better.

zqpm gravatar image zqpm  ( 2016-01-26 12:40:46 -0600 )edit

It may be helpful if you can post your CMakeLists.txt.

Akif gravatar image Akif  ( 2016-01-27 01:28:10 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2016-01-27 11:53:29 -0600

ARCHANA gravatar image

updated 2016-01-27 11:55:39 -0600

Adding following lines to your CMakeLists.txt will solve the problem. find_package(OpenCV your opencv version REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) And also add "${OpenCV_LIBRARIES}" with ${catkin_LIBRARIES} in target_link_libraries line. for eg. target_link_libraries(your cpp file name ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

edit flag offensive delete link more
0

answered 2016-01-27 08:05:03 -0600

zqpm gravatar image

updated 2016-01-27 09:41:10 -0600

Apparently a bunch of my OpenCV shared libraries were missing for some reason. Now reinstalled via 'apt-get install --reinstall ...' and compiling fine.

With the .so files missing the linker was trying to use the .a static libraries instead. My build knowledge is not that deep so I don't currently understand why that wouldn't work (in case anyone want to enlighten me).

edit flag offensive delete link more
0

answered 2016-01-26 16:48:04 -0600

MahdiehNejati gravatar image

I had the exact same error a few days ago. The first problem for me was that I had two different versions of OpenCV on my system, where the correct version had not been installed and built.

After making sure I have the correct version installed on my system, I had to add the correct path to the build directory in my .bashrc. Basically, I added this line to the end of my .bashrc:

export OpenCV_DIR=~/opencv/build

This fixed the problem for me. I hope it helps you as well!

edit flag offensive delete link more

Comments

I do have the repository version and a version I built from source (for some purpose I can't remember). Setting that env variable to did not redirect the linker to the source build for me, however.

zqpm gravatar image zqpm  ( 2016-01-27 09:44:59 -0600 )edit

Question Tools

Stats

Asked: 2016-01-26 10:01:38 -0600

Seen: 1,580 times

Last updated: Jan 27 '16