如何在 CMake Makefile 中包含 OpenCV 库

发布于 2024-10-28 21:21:22 字数 796 浏览 1 评论 0原文

我希望你能帮助我。

我有一个简单的 CMakeLists.txt,以便在 Leopard 10.5.8 上构建我的项目。 我正在使用 CMake 2.8.1,目前这是代码:

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 时,我将包含路径设置为 /opt/local/include 以及库路径:/opt/local/lib,然后指定库名称,例如_opencv_core、opencv_imgproc、opencv_video。

您能告诉我如何在 CMakeLists.txt 文件中添加这些信息吗?

我已阅读官方 cmake FAQ 中的一些信息,但无法解决我的问题。

请帮我。

多谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天冷不及心凉 2024-11-04 21:21:22

您需要在 TARGET_LINK_LIBRARIES 命令中添加库名称,但需要添加不带 lib 前缀的库名称。例如:

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})

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})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文