我正在创建C ++ Windows服务。 我想将Boost Process添加到我的应用程序中,但是由于某些原因,我不断收到此错误:
LINK:致命错误LNK1104:无法打开文件“ optimized.lib”
在尝试添加Boost之前,一切正常。当我打开Visual Studio解决方案时,我注意到该应用程序试图与我不熟悉的optimized.lib
和debug.lib
库进行链接。当我尝试添加Boost时,CMake仅尝试链接这些库。
我的目录结构:
UpdateService/
CMakeLists.txt
app/
CMakeLists.txt
Driver.cpp
build/
include/
stdafx.h
UpdateService/
# a bunch of *.h files
src/
CMakeLists.txt
# a bunch of *.cpp files
我的UpdateService/CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.12...3.14)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
project(UpdateService
VERSION 1.0
DESCRIPTION "Service that runs the update manager"
LANGUAGES CXX)
add_subdirectory(src)
add_subdirectory(app)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT UpdateService)
我的UpdateService/src/CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.12...3.14)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
set(FMT_DIR "E:/Repositories/fmt-5.3.0")
set(FMT_INCLUDE "${FMT_DIR}/include")
set(SPDLOG_INCLUDE "E:/Repositories/spdlog/include")
set(Boost_DEBUG ON)
# set(Boost_USE_STATIC_LIBS ON)
# set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost 1.67 REQUIRED COMPONENTS system filesystem)
# Needed to suppress a warning in boost process.
add_compile_definitions(_SCL_SECURE_NO_WARNINGS)
add_library(UpdateServiceLib STATIC
"${CMAKE_SOURCE_DIR}/include/stdafx.h"
"${CMAKE_SOURCE_DIR}/include/UpdateService/CLI11.hpp"
"${CMAKE_SOURCE_DIR}/include/UpdateService/Config.h"
"${CMAKE_SOURCE_DIR}/include/UpdateService/CmdParams.h"
"${CMAKE_SOURCE_DIR}/include/UpdateService/LogUtils.h"
"${CMAKE_SOURCE_DIR}/include/UpdateService/ServiceBase.h"
"${CMAKE_SOURCE_DIR}/include/UpdateService/UpdateService.h"
"${FMT_DIR}/src/format.cc"
"Config.cpp"
"CmdParams.cpp"
"LogUtils.cpp"
"ServiceBase.cpp"
"UpdateService.cpp")
target_include_directories(UpdateServiceLib PUBLIC
"${Boost_INCLUDE_DIRS}"
"${CMAKE_SOURCE_DIR}/include"
"${FMT_INCLUDE}"
"${SPDLOG_INCLUDE}")
target_link_libraries(UpdateServiceLib PUBLIC "${Boost_LIBRARIES}")
我的UpdateService/app/CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.12...3.14)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
add_executable(UpdateService "Driver.cpp")
target_include_directories(UpdateService
PRIVATE "${CMAKE_SOURCE_DIR}/include" "${FMT_INCLUDE}" "${SPDLOG_INCLUDE}")
target_link_libraries(UpdateService PRIVATE UpdateServiceLib)
我正在使用类似这样的项目来构建项目:
rmdir /S /Q build
mkdir build
mkdir build\x64
pushd build\x64
cmake -G "Visual Studio 14 2015 Win64" ..\..
cmake --build . --config Debug
popd
答案 0 :(得分:2)
删除${Boost_LIBRARIES}
周围的双引号。
双引号告诉CMake将封闭值视为单个参数,但是Boost_LIBRARIES
实际上是一个列表(多值变量)。
通常,双引号仅用于:
“字符串文字”(当参数不包含变量的取消引用时),例如
"abc"
当明确知道参数代表单个值时,例如
"${CMAKE_SOURCE_DIR}/include"
“ LIBRARIES”单词的复数表示Boost_LIBRARIES
变量可能包含多个值,因此请勿将其用双引号引起来。