LNK1104: 在 boost_python 版本为 1.72 时无法打开文件 'libboost_python27-vc142-mt-x64-1_71.lib'

LNK1104: cannot open file 'libboost_python27-vc142-mt-x64-1_71.lib' while boost_python version is 1.72

我正在使用 cmake 和 Visual Studio 2019 来构建我的项目。我的 boost 版本是 1.72,我在目录 boost_1_72_0\stage\lib 中生成了文件 libboost_python27-vc142-mt-x64-1_72.libb2.exe.

我用 cmake 生成了 .sln 文件。然后我在 Visual Studio 2019 年构建项目。但是, 它以错误结束 LNK1104: cannot open file 'libboost_python27-vc142-mt-x64-1_71.lib'

我真的不明白为什么它要求 libboost_python 版本 1_71 而不是 1_72。我从未在任何文件中引入版本 1.71 请求。那么应该如何呢?我怎样才能让它发挥作用?

我的 CMakeLists.txt 文件:

project(framecore)
cmake_minimum_required(VERSION 3.20)
message(STATUS "Configuring framecore")

set(Boost_USE_STATIC_LIBS ON)
# windows 
if(MSVC)
    # this although can be set by system variable Boost_INCLUDE_DIR etc
    set(Boost_INCLUDE_DIR F:/boost_1_72_0)
    set(Boost_LIBRARY_DIR F:/boost_1_72_0/stage/lib)
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(PythonLibs 2.7 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
find_package(Boost REQUIRED COMPONENTS container)
find_package(Boost REQUIRED COMPONENTS python27)

file(GLOB_RECURSE SRC src/core/*.cpp
        src/wraps/*.cpp)

file(GLOB_RECURSE SRC_HEADER src/core/*.hpp
        src/core/*.h
        src/wraps/*.hpp
        src/wraps/*.h)

include_directories(src)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})

message(STATUS "Boost Include path:  ${Boost_INCLUDE_DIRS}")
message(STATUS "Python2.7 Include path: ${PYTHON_INCLUDE_DIRS}")

if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_PYTHON_STATIC_LIB -DBOOST_USE_WINDOWS_H /bigobj")
    set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} /verbose:lib")
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/output)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/output)

add_library(${PROJECT_NAME} SHARED ${SRC_HEADER} ${SRC})

# set target library's prefix suffix
if(MSVC)
    set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
    set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".pyd")
endif()

message(STATUS "Boost_PYTHON27_LIBRARY:  ${Boost_PYTHON27_LIBRARY}")
# optimized;F:/boost_1_72_0/stage/lib/libboost_python27-vc142-mt-x64-1_72.lib;debug;F:/boost_1_72_0/stage/lib/libboost_python27-vc142-mt-gd-x64-1_72.lib

target_link_libraries(${PROJECT_NAME} ${Boost_PYTHON27_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${Boost_SYSTEM_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${Boost_CONTAINER_LIBRARY})

我现在知道原因了。在我的项目文件夹中还有另一个带有一些头文件的 boost 目录。我错误地包含了 boost 目录并依赖于 boost 1.71....