如何在CMake Makefile中包含OpenCV库 [英] How to include OpenCV libraries in CMake Makefile
问题描述
我希望你能帮助我。
我有一个简单的CMakeLists.txt为了构建我的项目Leopard 10.5.8。
我使用CMake 2.8.1,目前是代码:
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")
我需要在我的项目中添加OpenCV库。
当我使用Eclipse时,我将include路径设置为/ opt / local / include
,库路径设置为:/ opt / local / lib,然后指定库名称,例如__ opencv_core,opencv_imgproc,opencv_video
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.
您能告诉我如何在CMakeLists.txt文件中添加这些信息吗?
Can you tell me how to add these information in the CMakeLists.txt file, please?
我在官方的cmake常见问题中读到了一些信息,但我无法解决我的问题。
I've read some information in the official cmake FAQ but i wasn't able to solve my problem.
请帮帮我。
非常感谢。
推荐答案
您需要在TARGET_LINK_LIBRARIES命令中添加库名,添加他们没有lib前缀。例如:
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})
这篇关于如何在CMake Makefile中包含OpenCV库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!