Boost.Python can't find pyconfig.h. Where does it need to go?
16,009
Try command:
g++ -g -shared -fPIC -I/usr/include/python2.7 decision.cpp -lpython2.7 -lboost_python -o decision.so
Author by
kramer65
Updated on June 05, 2022Comments
-
kramer65 almost 2 years
I've written a very simple c++ function in main.cpp:
#include <iostream> using namespace std; int SomeCalculation(float x){ int decision = 0; if (x > 1){ decision = 1; } return decision; }
I'm now trying to compile this as a shared library using Boost.Python. For this I created decision.cpp:
#include <boost/python.hpp> BOOST_PYTHON_MODULE(decision) { using namespace boost::python; def("main", main); }
Unfortunately I get the following error:
In file included from /usr/include/boost/python/detail/prefix.hpp:13:0, from /usr/include/boost/python/args.hpp:8, from /usr/include/boost/python.hpp:11, from decision.cpp:1: /usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: File or folder does not exist. compilation terminated.
Since I had no clue of where this file could be I did a simple
sudo find / -name pyconfig.h
, which found several pyconfig.h files. So I simply copied what to me seemed the most general version of the file, to the folder in which I'm working:cp /usr/include/python2.7/pyconfig.h /home/kram/c++/cmod/pyconfig.h
Running my compile command again (
g++ -fPIC -g -ggdb -c decision.cpp -o decision.so
) gives me the same error as before though.Does anybody know how I can solve this pyconfig.h dependency?
[edit] Added pieces of code