gpt4 book ai didi

c++ - 导入库的 include_directories

转载 作者:太空狗 更新时间:2023-10-29 21:34:04 35 4
gpt4 key购买 nike

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

根目录/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 目标的目录?如何解决这个问题?

提前谢谢你。

最佳答案

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

add_library(nana_lib STATIC IMPORTED GLOBAL)

"The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility."

引用

关于c++ - 导入库的 include_directories,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48355884/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com