I'm getting the following error when trying to use Boost Python:
/usr/include/boost/python/object_core.hpp:400: undefined reference to `_Py_NoneStruct'
Installed on Ubuntu 18.04 using:
sudo apt-get install libboost-all-dev
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(boostpy)
set(CMAKE_CXX_STANDARD 14)
include_directories(/usr/include/python3.6)
find_package(Boost 1.65.1 COMPONENTS python3-py36 REQUIRED)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(boostpy main.cpp)
if(Boost_FOUND)
target_link_libraries(boostpy ${Boost_LIBRARIES})
endif()
main.cpp
#include <iostream>
#include <boost/python.hpp>
#include <Python.h>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
Results in:
-- Found Boost: /usr/include (found suitable version "1.65.1", minimum required is "1.65.1") found components: python3-py36
-- Boost_INCLUDE_DIRS: /usr/include
-- Boost_LIBRARIES: /usr/lib/x86_64-linux-gnu/libboost_python3-py36.so
-- Boost_VERSION: 106501
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tb/CLionProjects/boostpy/cmake-build-debug
[ 50%] Linking CXX executable boostpy
CMakeFiles/boostpy.dir/main.cpp.o: In function `boost::python::api::object::object()':
/usr/include/boost/python/object_core.hpp:400: undefined reference to `_Py_NoneStruct'
collect2: error: ld returned 1 exit status
CMakeFiles/boostpy.dir/build.make:95: recipe for target 'boostpy' failed
make[3]: *** [boostpy] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/boostpy.dir/all' failed
make[2]: *** [CMakeFiles/boostpy.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/boostpy.dir/rule' failed
make[1]: *** [CMakeFiles/boostpy.dir/rule] Error 2
Makefile:118: recipe for target 'boostpy' failed
make: *** [boostpy] Error 2