导入库的include_directories [英] include_directories for imported library
问题描述
我正在用C ++编写项目,并且在cmake中导入库时遇到问题。正在导入的第三方库不会传播包含目录。
I am writing project in c++, and I have problem with importing libraries in cmake. The third party library, which is importing, does not propagate include directories.
Root /CMakeLists.txt
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/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
Example of code /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 目标的包含目录?
如何解决该问题?
Why nana_lib target does not propagate include directories for camera_calib_exe target? How to solve that issue?
谢谢您。
推荐答案
导入目标的范围很重要。尝试将 GLOBAL
选项添加到 add_library()
:
The scope for imported target's is important. Try to add the GLOBAL
option to add_library()
:
add_library(nana_lib STATIC IMPORTED GLOBAL)
目标名称在创建它的目录及其下的目录中具有作用域,但是GLOBAL选项扩展了可见性。
"The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility."
参考
这篇关于导入库的include_directories的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!