我有一个奇怪的问题,Windows上的CMake运行没有问题,但编译器实际上没有创建库
project(core)
find_package(spdlog REQUIRED)
set(core_gen_hdr "include/chrono.h" "include/monitoring.h" "${SPDLOG_HEADER_FILES}")
add_library(${PROJECT_NAME} STATIC "${core_gen_hdr}")
target_include_directories (${PROJECT_NAME} PUBLIC "include/" "${SPDLOG_INCLUDE_DIRS}")
source_group("Header Files" FILES "${core_gen_hdr}")
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${MODULE_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
我想知道这是因为唯一的源文件是头文件吗?编译时,不会创建任何库,这会导致想要链接到不存在的文件的依赖库出现问题。
CMake版本是3.5.0,我使用Visual Studio 2015构建。
答案 0 :(得分:0)
您需要创建interface library
事实上,spdlog
也只是标题,并且这样做(见here)
对于您的项目,您只需添加项目的include目录,然后链接到spdlog
,cmake将整理传递依赖项
# create your library, specifying it is an interface-library
add_library(${PROJECT_NAME} INTERFACE)
# add your project's directories
target_include_directories(
${PROJECT_NAME}
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include)
# link against spdlog, which is also just an interface-library
target_link_libraries(${PROJECT_NAME} spdlog)