Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake link with libboost_python-py32.so instead of libboost_python.so

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'
like image 277
Alexander Kjäll Avatar asked Mar 03 '13 17:03

Alexander Kjäll


1 Answers

This might do the trick :

set(Python_ADDITIONAL_VERSIONS 3.2)

find_package(Boost COMPONENTS system thread python-py32 REQUIRED)
like image 82
Julien Hirel Avatar answered Nov 15 '22 05:11

Julien Hirel