3

I am trying to compile a tutorial project with Boost::python using cmake on windows.

I installed Boost using

.\b2 --with-python --toolset=msvc-14.1 architecture=x86 address-model=64 link=shared --user-config=user-config.jam

The user config contains

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
;

the cmake file is

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 is able to find the boost_python library

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

But I still get the following error during compilation:

LNK1104 cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc141-mt-gd-x64-1_67.lib'

Anybody have any insight on what is going on? why is the linker still unable to find the library file.

I am loosely following this guy's example.

2
  • 1
    MAJOR_VERSIONPY and MAJOR_VERSIONPY look like macros that haven't been defined properly, see Compile problems when trying to link to 1.67.0 python library #193 Commented Dec 5, 2018 at 4:44
  • @VTT thanks, I manually set the major and minor macro value and the thing now compiles. But loading the resulting pyd file in python creates an error. I guess that's another problem entirely XD Commented Dec 5, 2018 at 17:06

1 Answer 1

2

Thanks to VTT answer's, I needed to set the PY_MAJOR_VERSION and PY_MINOR_VERSION to the correct value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.