9

I'm trying to build python bindings for a library that i wrote, and i'm having some trouble getting cmake to understand that it should use the boost-python library for python 3.

Here is my cmake file:

cmake_minimum_required(VERSION 2.8)

FIND_PACKAGE(Boost COMPONENTS
                system
                thread
                python REQUIRED)
find_package(PythonLibs REQUIRED)

INCLUDE_DIRECTORIES(${PYTHON_LIBRARIES})
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})

ADD_LIBRARY(
  pschulze SHARED
  src/candidate_relation.cpp
  src/schulze.cpp
  src/calculate.cpp
  src/candidate.cpp
  src/ranking.cpp
  src/userinput.cpp
  python.cpp)

TARGET_LINK_LIBRARIES(pschulze ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

ADD_EXECUTABLE(
  schulze
  src/candidate_relation.cpp
  src/schulze.cpp
  src/calculate.cpp
  src/candidate.cpp
  src/ranking.cpp
  src/userinput.cpp
  src/json-spirit/json_spirit_reader.cpp
  src/json-spirit/json_spirit_value.cpp
  main.cpp)

TARGET_LINK_LIBRARIES(schulze ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

ADD_DEFINITIONS(-std=gnu++0x -Os)

add_subdirectory (tests)

set(CMAKE_BUILD_TYPE Debug)

And this is the linker error that I get:

Linking CXX executable schulze
CMakeFiles/schulze.dir/src/schulze.cpp.o: In function `arg_to_python':
/usr/include/boost/python/converter/builtin_converters.hpp:122: undefined reference to `PyInt_FromLong'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/libboost_python.so: undefined reference to `PyString_Size'
3
  • Does changing to find_package(PythonLibs 3 REQUIRED) work? You should probably delete your CMakeCache.txt before trying. Commented Mar 3, 2013 at 18:38
  • the builtin_converters.hpp:122 error disappeared, but the libboost_python.so: undefined reference to `PyString_Size' is still there. Commented Mar 3, 2013 at 18:59
  • @Fraser: find_package(PythonLibs 3 REQUIRED) won't help you to find the corresponding Boost.Python library. It finds the Python "basic" language libraries only. Commented Oct 7, 2016 at 14:13

1 Answer 1

6

This might do the trick :

set(Python_ADDITIONAL_VERSIONS 3.2)

find_package(Boost COMPONENTS system thread python-py32 REQUIRED)
Sign up to request clarification or add additional context in comments.

2 Comments

This may work e.g. on Ubuntu. But if you compile Boost from sources on the Mac, the library is called simply libboost_python3. May happen on other Linux distributions (e.g. Fedora) as well.
@user465139 where would you set that?

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.