Sign in to follow this  
TheComet

CMake - Force Boost.Python to link python 2.7

Recommended Posts

This is the situation:

  • Gentoo, Linux, gcc (Gentoo 4.7.3-r1 p1.4, pie-0.5.5) 4.7.3, cmake version 2.8.12.2
  • Python2.7 and Python3.3 installed
  • Built both libboost_python-2.7 and libboost_python-3.3

need to use python2.7 in my project. This is the cmake script I use to find the required python and boost components:

###############################################################################
# Python
message (STATUS "Looking for Python...")
find_package (PythonLibs 2.7 REQUIRED)
message (STATUS "Found Python: ${PYTHON_LIBRARIES}")
include_directories (${PYTHON_INCLUDE_DIRS})
target_link_libraries (Project ${PYTHON_LIBRARIES})


###############################################################################
# Boost - Ogre requires at least 1.46.0
find_package (Boost 1.46.0 REQUIRED COMPONENTS
    python)
include_directories (${Boost_INCLUDE_DIRS})
target_link_libraries (Project ${Boost_PYTHON_LIBRARY})
message (STATUS "python library is: ${Boost_PYTHON_LIBRARY}")

The output when running CMake is:

-- Looking for Python...
-- Found Python: /usr/lib64/libpython2.7.so
-- Boost version: 1.52.0
-- Found the following Boost libraries:
--   python
-- python library is: /usr/lib64/libboost_python-3.3-mt.so

How can I force boost to find python2.7 instead of 3.3?

Share this post


Link to post
Share on other sites

Try passing -DBoost_DEBUG=ON to your CMake command. This should cause the FindBoost module to output exactly what names it is searching for and in what order. This could be helpful in finding out why it finds 3.3 and not 2.7. From a look at FindBoost I can't see any options to specify the Python Version.

Share this post


Link to post
Share on other sites

It seems to find both versions of the library, but FindBoost.cmake will choose the higher version and there's no way to tell it to do otherwise.

 

Currently, I'm using the following as a workaround in my own CMake script:

                # hack to force boost to use python2.7
                string (REGEX REPLACE "[0-9].[0-9]" "2.7" Boost_PYTHON_LIBRARY ${Boost_PYTHON_LIBRARY})

Share this post


Link to post
Share on other sites


It seems to find both versions of the library, but FindBoost.cmake will choose the higher version and there's no way to tell it to do otherwise.

Currently, I'm using the following as a workaround in my own CMake script:

# hack to force boost to use python2.7string (REGEX REPLACE "[0-9].[0-9]" "2.7" Boost_PYTHON_LIBRARY ${Boost_PYTHON_LIBRARY})

Your regular expression is searching for numeric any numeric - you need to escape the period - i.e. [0-9]\\.[0-9]

You should be able to use EXACT when searching for the package to specify a specific version:

find_package (PythonLibs 2.7 EXACT REQUIRED)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this