使用 Boost::Python、cmake 和 windows 编译
Compiling with Boost::Python, cmake and windows
我正在尝试使用 Boost::python 在 windows 上使用 cmake 编译教程项目。
我使用
安装了 Boost
.\b2 --with-python --toolset=msvc-14.1 architecture=x86 address-model=64 link=shared --user-config=user-config.jam
用户配置包含
import toolset : using ;
using python
: 3.6 # Version
: C:/ProgramData/Anaconda3/python.exe # Interpreter
: C:/ProgramData/Anaconda3/include/include # inc dir
: C:/ProgramData/Anaconda3/libs # link libs
: <toolset>msvc
;
cmake 文件是
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0074 NEW)
project(tutorial)
# Find default python libraries and interpreter
find_package(Boost REQUIRED)
find_package(PythonInterp 3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)
include_directories(${Boost_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.67 REQUIRED COMPONENTS python36)
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
# Build and link the pylib module
add_library(pylib MODULE pylib.cpp)
set_target_properties(pylib PROPERTIES SUFFIX .pyd)
target_link_libraries(pylib ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
cmake 能够找到 boost_python 库
Boost_LIBRARIES = optimized;C:/Program Files/boost/boost_1_67_0/stage/lib/boost_python36-vc141-mt-x64-1_67.lib;debug;C:/Program Files/boost/boost_1_67_0/stage/lib/boost_python36-vc141-mt-gd-x64-1_67.lib
但是我在编译的时候还是报了如下错误:
LNK1104 cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc141-mt-gd-x64-1_67.lib'
有人知道发生了什么事吗?为什么链接器还是找不到库文件
我正在松散地关注这个人的 example。
感谢 VTT 的回答,我需要将 PY_MAJOR_VERSION
和 PY_MINOR_VERSION
设置为正确的值。
我正在尝试使用 Boost::python 在 windows 上使用 cmake 编译教程项目。
我使用
安装了 Boost.\b2 --with-python --toolset=msvc-14.1 architecture=x86 address-model=64 link=shared --user-config=user-config.jam
用户配置包含
import toolset : using ;
using python
: 3.6 # Version
: C:/ProgramData/Anaconda3/python.exe # Interpreter
: C:/ProgramData/Anaconda3/include/include # inc dir
: C:/ProgramData/Anaconda3/libs # link libs
: <toolset>msvc
;
cmake 文件是
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0074 NEW)
project(tutorial)
# Find default python libraries and interpreter
find_package(Boost REQUIRED)
find_package(PythonInterp 3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)
include_directories(${Boost_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.67 REQUIRED COMPONENTS python36)
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
# Build and link the pylib module
add_library(pylib MODULE pylib.cpp)
set_target_properties(pylib PROPERTIES SUFFIX .pyd)
target_link_libraries(pylib ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
cmake 能够找到 boost_python 库
Boost_LIBRARIES = optimized;C:/Program Files/boost/boost_1_67_0/stage/lib/boost_python36-vc141-mt-x64-1_67.lib;debug;C:/Program Files/boost/boost_1_67_0/stage/lib/boost_python36-vc141-mt-gd-x64-1_67.lib
但是我在编译的时候还是报了如下错误:
LNK1104 cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc141-mt-gd-x64-1_67.lib'
有人知道发生了什么事吗?为什么链接器还是找不到库文件
我正在松散地关注这个人的 example。
感谢 VTT 的回答,我需要将 PY_MAJOR_VERSION
和 PY_MINOR_VERSION
设置为正确的值。