首页 > 解决方案 > 如何在 C++ 中正确添加库?

问题描述

对于我的 C++ 项目,我的目录结构如下(项目名称是“分类”):

我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(taxonomy)

set(CMAKE_CXX_STANDARD 14)

add_executable(taxonomy main.cpp)
target_include_directories(taxonomy PUBLIC some_library)

我面临的问题是 all.hpp 有类似 #include "subdirectory/someCode.cpp" 的代码。在我的主要功能中我写“#include”some_library/include/all.hpp“”然后它不会找到那些文件。我想我必须以某种方式告诉 CMakeLists 我想将路径“some_library/include”添加为“主路径”。但是我该怎么做呢?

标签: c++cmake

解决方案


推荐阅读