gpt4 book ai didi

windows - 尝试添加 Boost Process 时 cmake 无法打开文件 optimized.lib

转载 作者:行者123 更新时间:2023-12-03 11:08:42 26 4
gpt4 key购买 nike

我正在创建一个 C++ Windows 服务。我想将 Boost Process 添加到我的应用程序中,但由于某种原因,我不断收到此错误:

LINK : fatal error LNK1104: cannot open file 'optimized.lib'

在我尝试添加 Boost 之前一切正常。当我打开我的 Visual Studio 解决方案时,我注意到该应用程序正在尝试链接我不熟悉的 optimized.libdebug.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

最佳答案

删除 ${Boost_LIBRARIES} 周围的双引号

双引号告诉 CMake 将包含的值视为单个参数,但 Boost_LIBRARIES 实际上是一个列表(多值变量)。


通常,双引号仅用于:

  • “字符串文字”(当参数不包含变量的解引用),例如

    "abc"
  • 当明确知道参数表示单个值时,例如

    "${CMAKE_SOURCE_DIR}/include"

“LIBRARIES”一词的复数表示 Boost_LIBRARIES 变量可能包含多个值,因此不要用双引号括起来。

关于windows - 尝试添加 Boost Process 时 cmake 无法打开文件 optimized.lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55459078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com