如何将存储在磁盘上的第三方项目正确地包含到我的cmake项目中?

时间:2019-06-11 10:16:50

标签: cmake

我有一个使用cmake的项目,并希望在其中包含opencv。我需要从./third_party/opencv的本地磁盘中使用此依赖项。我有git repo内容https://github.com/opencv/opencv

我是CMake的新手,不知道如何在我的项目中加入这个项目。

我已经尝试了各种方法,最近将其添加到了CMakeLists.txt include_directories(${PROJECT_SOURCE_DIR}/third_party/opencv)中。哪个不起作用。我收到如下错误:

 undefined reference to `cv::rectangle(cv::Mat&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)

这是我的完整CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(root)

include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)

FIND_PACKAGE(PkgConfig REQUIRED)

find_package(ZXing CONFIG)

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

include_directories(
  ${PROJECT_SOURCE_DIR}/third_party
)
include_directories(${PROJECT_SOURCE_DIR}/third_party/opencv)

add_executable(application ${PROJECT_SOURCE_DIR}/main.cpp)
add_executable(run_tests ${PROJECT_SOURCE_DIR}/tests/tests.cpp)
target_link_libraries(
  application
  ${GTEST_LIBRARIES} pthread ${ZBAR_LIBRARIES} ZXingCore
)
target_link_libraries(
  run_tests
  ${GTEST_LIBRARIES} pthread ${ZBAR_LIBRARIES} ZXingCore
)

关于如何正确执行此操作的任何想法?谢谢

0 个答案:

没有答案