Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Python can't find pyconfig.h. Where does it need to go?

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

like image 419
kramer65 Avatar asked Nov 21 '25 04:11

kramer65


1 Answers

Try command:

g++ -g -shared -fPIC -I/usr/include/python2.7 decision.cpp -lpython2.7 -lboost_python -o decision.so
like image 188
Tsar Ioann Avatar answered Nov 22 '25 17:11

Tsar Ioann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!