I've the following boost:python code(gona.cpp).
#include <iostream>
using namespace std;
void say_hello(const char* name) {
cout << "Hello " << name << "!\n";
}
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
def("say_hello", say_hello);
}
int main(){
return 0;
}
I have boost 1.47(boost pro) installed in my system(Windows 7 32-bit). I used Microsoft Visual Studio 2010 to build this and it has been built successfully. But I want to use this in a python code (as an import). I have the following piece of code (setup.py) to build this into a python module.
from distutils.core import setup
from distutils.extension import Extension
setup(name="PackageName",
ext_modules=[
Extension("hello", ["gona.cpp"],
libraries = ["boost_python", "boost"])
])
"gona" is the file C++ file name. I used the following command to build this in the command line.
python setup.py build
After I do this, I get the following error.
>python setup.py build
running build
running build_ext
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c De
cision_Tree.cpp -o build\temp.win32-2.7\Release\gona.o
gona.cpp:9:35: fatal error: boost/python/module.hpp: No such file or di
rectory
compilation terminated.
error: command 'gcc' failed with exit status 1
It seems the boost installation I have in my system works only on Visual studio(as it had been built successfully). I've run other boost programs without problems in Visual studio. How do I build this as a python module, so that it can be imported in python code?. (Using command line or Visual studio)
Several things here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.