include_directories用于导入的库

时间:2018-01-20 12:01:06

标签: c++ cmake nana

我正在用c ++编写项目,我在cmake中导入库时遇到问题。正在导入的第三方库不会传播包含目录。

Root /CMakeLists.txt

# Top level CMakeLists.txt

cmake_minimum_required(VERSION 3.9.2 FATAL_ERROR)
project(camera_calib)

add_subdirectory(${PROJECT_SOURCE_DIR}/nana)

file(GLOB SRC "${PROJECT_SOURCE_DIR}/src/*.cpp")

add_executable(camera_calib_exe ${SRC})

target_include_directories(camera_calib_exe PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(camera_calib_exe nana_lib)

/nana/CMakeLists.txt

# nana c++ gui CMakeLists.txt

cmake_minimum_required(VERSION 3.9.2 FATAL_ERROR)
project(nana VERSION 1.5.6 LANGUAGES CXX)

add_library(nana_lib STATIC IMPORTED)
set_property(TARGET nana_lib PROPERTY IMPORTED_IMPLIB_DEBUG ${PROJECT_SOURCE_DIR}/lib/nana_v141_Debug_x64.lib)
set_property(TARGET nana_lib PROPERTY IMPORTED_IMPLIB_RELEASE ${PROJECT_SOURCE_DIR}/lib/nana_v141_Release_x64.lib)
set_property(TARGET nana_lib PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include)
#set_property(TARGET nana_lib PROPERTY INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include)

代码示例/src/main.cpp

#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>

int main(int argc, char** argv)
{
    nana::form fm(nana::rectangle(0, 0, 1900, 1000));
    fm.caption("Camera Calibration");

    nana::button btn_openCam(fm, nana::rectangle(1770, 20, 100, 30));
    btn_openCam.caption("Open cameras");
    btn_openCam.events().click(nana::API::exit_all);

    nana::button btn_closeCam(fm, nana::rectangle(1770, 20 + 30 + 20, 100, 30));
    btn_closeCam.enabled(false);
    btn_closeCam.caption("Close cameras");
    btn_closeCam.events().click(nana::API::exit_all);

    nana::button btn_exit(fm, nana::rectangle(1770, 900, 100, 30));
    btn_exit.caption("Exit");
    btn_exit.events().click(nana::API::exit_all);
    fm.show();
    nana::exec();

    std::cout << "lala";
    return 0;

}

错误列表是:

E1696   cannot open source file "nana/gui.hpp"
E1696   cannot open source file "nana/gui/widgets/label.hpp"
E1696   cannot open source file "nana/gui/widgets/button.hpp"

为什么 nana_lib 目标不会传播包含 camera_calib_exe 目标的目录? 如何解决这个问题?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

导入目标的范围很重要。尝试将GLOBAL选项添加到add_library()

add_library(nana_lib STATIC IMPORTED GLOBAL)
  

“目标名称在创建它的目录中具有范围,在下面,但GLOBAL选项扩展了可见性。”

<强>参考