Ask Your Question
0

Trouble linking opencv libraries

asked 2017-02-04 20:09:15 -0600

Hi,

I'm just getting started with OpenCV. I want to use OpenCV for a machine vision project. I started by following the tutorial here:

as able to download the OpenCV repo from Github and compile it without to much trouble. OpenCV (3.2.0) is installed.

I started by following the tutorial here: docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage

I entered the code correctly, and then made the CMake file.

Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV COMPONENTS core imgproc highgui REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
LINK_DIRECTORIES("/usr/local/lib")
include_directories(${OpenCV_INCLUDE_DIR})

I tried making the project but it seems there is a library linking error. I'm a novice and am having trouble ascertaining if it is a version conflict, libraries missing, or just the linker is looking for libraries in the wrong place.

Here is the output when the make command is made:

pi@raspberrypi:~/Programming/build $ make
[ 50%] Linking CXX executable DisplayImage
/usr/bin/ld: CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: undefined     reference to symbol    '_ZN2cv6imreadERKNS_6StringEi'
/usr/local/lib/libopencv_imgcodecs.so.3.2: error adding symbols: DSO  missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/DisplayImage.dir/build.make:97: recipe for target  'DisplayImage' failed
make[2]: *** [DisplayImage] Error 1
CMakeFiles/Makefile2:67: recipe for target   'CMakeFiles/DisplayImage.dir/all' failed
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Looks like the problem is with the libopencv_imgcodecs.so.3.2. Any ideas?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-04 20:24:44 -0600

berak gravatar image

if it is a version conflict, libraries missing,

BOTH of it !

with opencv3, imread(), imwrite() and friends have been moved from highgui to a seperate imgcodecs module.

try:

find_package( OpenCV COMPONENTS core imgproc imgcodecs highgui REQUIRED )

also, please use http://docs.opencv.org/master/ , not the outdated 2.4 docs.

edit flag offensive delete link more

Comments

Ok awesome Berak! Thank you so much! Your help is greatly appreciated!

frankieforceps gravatar imagefrankieforceps ( 2017-02-04 22:38:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-04 20:09:15 -0600

Seen: 1,114 times

Last updated: Feb 04 '17