公共标头未找到其他公共标头

Public headers not finding other public headers

本文关键字:其他      更新时间:2023-10-16

我已经使用cmake创建了一个静态库,并且我正在以/usr/local/include/include//includ/。库及其测试单独编译,但是当在另一个项目中使用库时,我会遇到一个错误:

/usr/local/include/weftworks/common/network/tcp/acceptor.hpp:28:10: fatal error: utility.hpp: No such file or directory
 #include "utility.hpp"

ancorpor.hpp和utility.hpp都是公共标题。
这是相关的文件夹结构:

root/
├ cmake/
├ external/
├ library/
│ ├─ include/
│ │  ├─ network/
│ │  │  └─ tcp/
│ │  │     └─ acceptor.hpp
│ │  └─ utility.hpp
│ ├─ src/
│ └─ CMakeLists.txt
├ test/
└ CMakeLists.txt

./library/cmakelists.txt:

# ./library/CMakeLists.txt
# Required CMake version
cmake_minimum_required(VERSION 3.13)
include(GNUInstallDirs)
# Project details
project(
        weftworks-common-library
        VERSION         0.4.0
        DESCRIPTION     "Internal Weftworks Common Library project."
)
# Library target sources
list(APPEND WEFTWORKS_COMMON_LIBRARY_PRIVATE_SOURCES)
list(APPEND WEFTWORKS_COMMON_LIBRARY_PUBLIC_SOURCES)
list(APPEND WEFTWORKS_COMMON_LIBRARY_INTERFACE_SOURCES)
include(src/CMakeLists.txt)
# A static library target
add_library(weftworks-common-library STATIC)
# Required compiler features
target_compile_features(
        weftworks-common-library
        PUBLIC
                cxx_auto_type
                cxx_constexpr
                cxx_defaulted_functions
                cxx_deleted_functions
                cxx_final
                cxx_lambdas
                cxx_noexcept
                cxx_override
                cxx_range_for
                cxx_static_assert
                cxx_std_17
                cxx_strong_enums
                cxx_trailing_return_types
                cxx_uniform_initialization
                cxx_variadic_macros
)
target_compile_options(
        weftworks-common-library
        PRIVATE
                -Wall
                -Wextra
                -pedantic
)
target_include_directories(
        weftworks-common-library
        PUBLIC
                "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
                "$<INSTALL_INTERFACE:include>"
)
target_link_libraries(
        weftworks-common-library
        PUBLIC
                Boost::boost
                Boost::system
                Boost::program_options
                spdlog::spdlog
                Threads::Threads
)
target_sources(
        weftworks-common-library
        PUBLIC          ${WEFTWORKS_COMMON_LIBRARY_PUBLIC_SOURCES}
        INTERFACE       ${WEFTWORKS_COMMON_LIBRARY_INTERFACE_SOURCES}
        PRIVATE         ${WEFTWORKS_COMMON_LIBRARY_PRIVATE_SOURCES}
)
# Create alias target
add_library(weftworks::common-library ALIAS weftworks-common-library)
# Install library target
install(
        TARGETS                         weftworks-common-library
        EXPORT                          weftworks-common-library-config
        ARCHIVE DESTINATION             ${CMAKE_INSTALL_LIBDIR}
        PUBLIC_HEADER DESTINATION       ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
        EXPORT          weftworks-common-library-config
        NAMESPACE       weftworks::
        DESTINATION     ${CMAKE_INSTALL_LIBDIR}/weftworks/common-library
)
# Install public headers
install(
        DIRECTORY       ${CMAKE_CURRENT_SOURCE_DIR}/include/
        DESTINATION     ${CMAKE_INSTALL_INCLUDEDIR}/weftworks/common
)

现在,我不知道要做这项工作需要做什么。我想避免在项目结构(即library/include/weftworks/common/)中具有"库前缀",以使其保持简单。

您需要包括"weftworks/common/network/utility.hpp"

这还将确保您实际上包括您的标题,而不是某人写的其他标题,而这些标题很通用名称"utility.hpp"

相关文章: