首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >公共标头找不到其他公共标头

公共标头找不到其他公共标头
EN

Stack Overflow用户
提问于 2019-03-14 18:13:01
回答 1查看 68关注 0票数 0

我使用CMake创建了一个静态库,并将公共头文件安装在/usr/local/include/中。这个库和它的测试本身编译得很好,但是当在另一个项目中使用这个库时,我得到一个错误:

代码语言:javascript
复制
/usr/local/include/weftworks/common/network/tcp/acceptor.hpp:28:10: fatal error: utility.hpp: No such file or directory
 #include "utility.hpp"

其中acceptor.hpp和utility.hpp都是公共标头。

下面是相关的文件夹结构:

代码语言:javascript
复制
root/
├ cmake/
├ external/
├ library/
│ ├─ include/
│ │  ├─ network/
│ │  │  └─ tcp/
│ │  │     └─ acceptor.hpp
│ │  └─ utility.hpp
│ ├─ src/
│ └─ CMakeLists.txt
├ test/
└ CMakeLists.txt

./library/CMakeLists.txt:

代码语言:javascript
复制
# ./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/

EN

回答 1

Stack Overflow用户

发布于 2019-03-14 18:24:12

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

这还将确保您实际上包含了您的头,而不是某些人用非常通用的名称"utility.hpp"编写的其他头。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55159854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档