0

Hi I'm having some problems with using cmake to build this example. This is what I have:

├── _build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   ├── cmake_install.cmake
│   └── Makefile
├── CMakeLists.txt
├── hello_ext.cpp
└── README.md

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16.3)

project(test)

# Find python and Boost - both are required dependencies
find_package(PythonLibs 3.8 REQUIRED)
find_package(Boost COMPONENTS python38 REQUIRED)

# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")

# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(hello_ext MODULE hello_ext.cpp)

# Set up the libraries and header search paths for this target
target_link_libraries(hello_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(hello_ext PRIVATE ${PYTHON_INCLUDE_DIRS})

hello_ext.cpp:

#include <boost/python.hpp>

char const* greet()
{
  return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
  using namespace boost::python;
  def("greet", greet);
}

When I run cmake .. I get the following:

CMake Error at /usr/local/lib/cmake/Boost-1.77.0/BoostConfig.cmake:141 (find_package):
  Could not find a configuration file for package "boost_python" that exactly
  matches requested version "1.77.0".

  The following configuration files were considered but not accepted:

    /usr/lib/x86_64-linux-gnu/cmake/boost_python-1.71.0/boost_python-config.cmake, version: 1.71.0
    /lib/x86_64-linux-gnu/cmake/boost_python-1.71.0/boost_python-config.cmake, version: 1.71.0

Call Stack (most recent call first):
  /usr/local/lib/cmake/Boost-1.77.0/BoostConfig.cmake:258 (boost_find_component)
  /usr/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:7 (find_package)


I've tried the answers on this question.

I don't really know what is going wrong. It seems like I don't have boost_python-1.77.0, does that even exist? Maybe I need to tell CMake to use boost 1.71? Any help is appreciated.

catmousedog
  • 154
  • 1
  • 8
  • 1
    Smells like you have a config file `/usr/local/lib/cmake/Boost-1.77.0/BoostConfig.cmake` for Boost 1.77 but have no other files for that Boost installation. If it is so, then just remove that config file and try to build your project again. – Tsyvarev Dec 16 '21 at 22:04
  • That worked, thank you so much! Amazing how you knew that. – catmousedog Dec 16 '21 at 22:11

1 Answers1

0

As Tsyvarev posted in the comments I just had to removed the config file in /usr/local/lib/cmake/Boost-1.77.0/BoostConfig.cmake and rebuild my project.

catmousedog
  • 154
  • 1
  • 8