gpt4 book ai didi

c++ - 如何使用 CMake 从根文件夹外部添加包含目录?

转载 作者:搜寻专家 更新时间:2023-10-31 02:17:49 24 4
gpt4 key购买 nike

这是我的第一个 CMakeLists.txt 代码:

#cmake_minimum_required (VERSION 2.6)
project (project)

add_subdirectory(src)

include_directories(${/path_to_directory}/include)

这是子目录下的CMakeLists.txt

set (CMAKE_C_FLAGS "-WALL -g")

file(GLOB SRCS *.cpp *.hpp *.h)

add_executable(source ${SRCS})

我仍然无法在我的项目中包含 path_to_directory

编辑:这也不起作用:

file(GLOB mylib *.cpp *.hpp *.h)

add_executable(includeSource ${mystuff})
target_include_directories(
mystuff
PUBLIC ${path_to_directory}/include
)

最佳答案

即使问题不清楚,我猜你想要 target_include_directories(here 文档)而不是 include_directories

来自文档:

Specify include directories or targets to use when compiling a given target.

您可以将其用作:

target_include_directories(
your_target_name
PUBLIC ${/path_to_directory}/include
)

关于c++ - 如何使用 CMake 从根文件夹外部添加包含目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35258919/

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