0

I'm using cmake and Visual Studio 2019 to build my project. My boost version is 1.72 and I generated file libboost_python27-vc142-mt-x64-1_72.lib in directory boost_1_72_0\stage\lib with b2.exe.

I generated .sln file with cmake. Then I build the project in Visual Studio 2019. However, it ended up with an error LNK1104: cannot open file 'libboost_python27-vc142-mt-x64-1_71.lib'

I really can't understand why it asks for libboost_python of version 1_71 instead of 1_72. I never introduced a version 1.71 request in any file. So how should it be like that? And how can I make it work?

My CMakeLists.txt file:

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})
dylanchu
  • 11
  • 2
  • When you build, does it show the command line parameters getting passed to LINK.exe ? That will give all the hints about what library paths (`/L` option) are getting passed. – selbie Mar 10 '22 at 08:55
  • @selbie what do you mean by `/L` option? I tried to put `/L` to Linker-CommandLine-AddtionalOptions (`%(AdditionalOptions) /machine:x64 /verbose:lib /L`), but output said `/L` option is unrecognizable and ignored. verbose option gave these information: looking for `F:\boost_1_72_0\stage\lib\libboost_python27-vc142-mt-x64-1_72.lib:`, `C:\Python27\libs\python27.lib:`, `libboost_system...`, `libboost_container...`, `... kernel32 and 9more libs...`, `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64\msvcprt.lib:`, THEN, error LNK1104 was reported – dylanchu Mar 10 '22 at 10:27
  • Sorry, I think I meant `/LIBPATH`, not `/L`. Anyway, turn on verbose build output using the instructions [here](https://stackoverflow.com/a/57968430/104458) then inspect the link.exe command line from the build output. – selbie Mar 10 '22 at 16:34
  • Oh I think I know the reason now. I wrongly included a folder where there is a folder called boost with some header files in it. Maybe there some file was included and made a dependency on boost 1.71... – dylanchu Mar 11 '22 at 14:51

1 Answers1

1

I know the reason now. There is another boost directory with some header files in my project folder. I wrongly included the boost directory and made a dependency on boost 1.71....

dylanchu
  • 11
  • 2
  • Hi dylanchu, glad to know you've found the solution to resolve this issue! Please consider answering it and accepting it as an answer to change its status to Answered. It will also help others to solve a similar issue. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Yujian Yao - MSFT Mar 14 '22 at 09:25