Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include OpenCV libraries in CMake Makefile

I hope you can help me.

I have a simple CMakeLists.txt in order to build my project on Leopard 10.5.8. I'm using CMake 2.8.1 and at the moment this is the code:

cmake_minimum_required(VERSION 2.8)
MESSAGE(STATUS "./src: Going into utils folder")
ADD_SUBDIRECTORY(utils)
MESSAGE(STATUS "./src: utils folder processed")

include_directories(${DIR}/headers)
link_directories (${DIR}/src/utils)

ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample libSample ${EXTERNAL_LIBS})
INSTALL(TARGETS sample DESTINATION "./src")
MESSAGE(STATUS "./src: exiting src folder")

I need to add OpenCV libraries on my project. When I use Eclipse I set the include path to /opt/local/include and the libraries path to: /opt/local/lib and then I specify the libraries name such as_ opencv_core, opencv_imgproc, opencv_video.

Can you tell me how to add these information in the CMakeLists.txt file, please?

I've read some information in the official cmake FAQ but i wasn't able to solve my problem.

Please, help me.

Thanks a lot.

like image 574
Marcus Barnet Avatar asked Mar 31 '11 16:03

Marcus Barnet


1 Answers

You need to add the library names in the TARGET_LINK_LIBRARIES command, but you need to add them without the lib prefix. For example:

include_directories(${DIR}/headers /opt/local/include)
link_directories (${DIR}/src/utils /opt/local/lib)

ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample opencv_core opencv_imgproc opencv_video ${EXTERNAL_LIBS})
like image 170
ltc Avatar answered Oct 22 '22 08:10

ltc