我已经使用CMake创建了一个静态库,并且正在/ usr / local / include /中安装公共头文件。该库及其测试可以自行编译,但是在另一个项目中使用该库时会出现错误:
/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都是公共标头。
这是相关的文件夹结构:
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/
以保持简单。
答案 0 :(得分:0)
您需要包括"weftworks/common/network/utility.hpp"
。
这还将确保您实际上包含标头,而不是别人用通用名称"utility.hpp"
编写的其他标头。