Ask Your Question
0

Linking openCV library in CMake ubuntu

asked 2018-11-30 00:56:11 -0600

blessme29 gravatar image

updated 2018-11-30 01:04:31 -0600

berak gravatar image

Hello, I am trying to link the octomap library with openCV library, but I have problem when I tried to generate the file using cmake. I confused about this problem, this is the error when I "make" my project file :

[ 47%] Linking CXX executable ../../../bin/simple_example
CMakeFiles/simple_example.dir/simple_example.cpp.o: In function `cv::Mat::~Mat()':
simple_example.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x15): undefined reference to `cv::Mat::deallocate()'
simple_example.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x71): undefined reference to `cv::fastFree(void*)'
collect2: error: ld returned 1 exit status
octomap/src/CMakeFiles/simple_example.dir/build.make:96: recipe for target '../bin/simple_example' failed
make[2]: *** [../bin/simple_example] Error 1
CMakeFiles/Makefile2:1450: recipe for target 'octomap/src/CMakeFiles/simple_example.dir/all' failed
make[1]: *** [octomap/src/CMakeFiles/simple_example.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

And this is my CMakeList.txt file :

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT( octomap-distribution )

find_package( OpenCV REQUIRED )
set(OpenCV_DIR "/usr/local/include/opencv")
include_directories(${OpenCV_INCLUDE_DIRS})

ENABLE_TESTING()  # enable CTest environment of subprojects
set(CMAKE_POSITION_INDEPENDENT_CODE ON)  # enables -fPIC in applicable compilers (required to avoid link errors in some cases)

option(BUILD_OCTOVIS_SUBPROJECT "Build targets from subproject octovis" ON)
option(BUILD_DYNAMICETD3D_SUBPROJECT  "Build targets from subproject dynamicEDT3D" ON)
option(OCTOVIS_QT5 "Link Octovis against Qt5?" NO)

if(OCTOVIS_QT5)
    # Compiling against QT5 requires C++11.
    set(CMAKE_CXX_STANDARD 11)
endif(OCTOVIS_QT5)

ADD_SUBDIRECTORY( octomap )

if(BUILD_OCTOVIS_SUBPROJECT)
    ADD_SUBDIRECTORY( octovis )
endif()     

if(BUILD_DYNAMICETD3D_SUBPROJECT)   
    ADD_SUBDIRECTORY( dynamicEDT3D )
endif()

I already try to link the openCV library into the cmakelist file but it totally failed, Is there anyone had experience solve this problem?? I am using opencv 3.3 and ubuntu 16.04

Thank you very much

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-11-30 01:08:45 -0600

berak gravatar image

have a look here , you never link the opencv libraries. it needs an additional line like:

target_link_libraries(octovis ${OpenCV_LIBS})

(replace octovis with whichever of your projects there uses opencv)

edit flag offensive delete link more

Comments

Hello, thanks for replying I have tried to add the line but it still give me this following error :

user@pc:~/octomap/build$ cmake ..
CMake Error at CMakeLists.txt:8 (target_link_libraries):
  Cannot specify link libraries for target "simple_example" which is not
  built by this project.

-- Configuring incomplete, errors occurred!
See also "/home/ferdyan/octomap/build/CMakeFiles/CMakeOutput.log".

Actually my file is simple_example.cpp and if I build it using cmake it will create simple_example executable file. I want to add opencv function in the simple_example.cpp and build it, but it failed when I build it. The original CMakeList.txt file is this file : https://github.com/OctoMap/octomap/bl... I have tried try much way but it failed. Do

blessme29 gravatar imageblessme29 ( 2018-11-30 01:23:33 -0600 )edit

indeed, you cmake file never mentions simple_example

berak gravatar imageberak ( 2018-11-30 01:26:14 -0600 )edit

oh right, I just realize there is another CMakeList.txt file in the octomap sub folder, I will try it link the opencv library in the another CMakeList.txt file.

blessme29 gravatar imageblessme29 ( 2018-11-30 01:45:12 -0600 )edit
1

Hi, thanks for your answer, now I successfully connected the octomap with the openCV library, there are another cmakelist file in my project file Appreciate it, thank you very much

blessme29 gravatar imageblessme29 ( 2018-11-30 09:56:58 -0600 )edit

oh, cool ;)

berak gravatar imageberak ( 2018-11-30 10:07:20 -0600 )edit

Thx that's help me a lot

Aurelien_TT gravatar imageAurelien_TT ( 2018-12-26 07:23:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-30 00:56:11 -0600

Seen: 5,186 times

Last updated: Nov 30 '18