Así que estoy tratando de interactuar con python 3.2 y C++ usando boost python, y he encontrado muchos problemas. Finalmente lo compilé usando las bibliotecas 2.7 y funciona, pero parece que no puedo hacerlo funcionar con Python 3.2.Hola mundo con boost python y python 3.2
Aquí está el código C++
#include <iostream>
using namespace std;
void say_hello(const char* name) {
cout << "Hello " << name << "!\n";
}
int main(){return 0;}
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
def("say_hello", say_hello);
}
Si puedo compilar usando los 2,7 bibliotecas funciona muy bien, pero cuando se utiliza las bibliotecas 3.2 consigo toneladas de referencias indefinidas de libboost_python.so
lo contrario escribí un poco de Python para hacer que funcione:
from distutils.core import setup
from distutils.extension import Extension
setup(name="PackageName",
ext_modules=[
Extension("hello", ["testBoost.cpp"],
libraries = ["boost_python"])
])
y esto creará un modo usando Python 3.2 o 2.7 build, pero cuando abro la interpr Python 3 eter e intento importar el valor para que me dé el error indefinido símbolo PyClass_Type de libboost_python.so nuevamente. ¿Algunas ideas? ¿Es boost python compatible con Python 3.x?
Si la información es útil, aquí está mi intento de compilación usando 3.2:
$ g++ testBoost.cpp -I/usr/include/python3.2 -I/usr/local/include/boost/python -lboost_python -lpython3.2mu
/tmp/ccdmU1Yu.o: In function `PyInit_hello':
testBoost.cpp:(.text+0xc2): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_Size'
/usr/local/lib/libboost_python.so: undefined reference to `PyFile_FromString'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_Type'
/usr/local/lib/libboost_python.so: undefined reference to `PyInt_Type'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_FromString'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/local/lib/libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/local/lib/libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/local/lib/libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/local/lib/libboost_python.so: undefined reference to `PyInt_AsLong'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_InternFromString'
/usr/local/lib/libboost_python.so: undefined reference to `PyClass_Type'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_AsString'
/usr/local/lib/libboost_python.so: undefined reference to `PyInt_FromLong'
/usr/local/lib/libboost_python.so: undefined reference to `PyFile_AsFile'
collect2: ld returned 1 exit status
Y el error del intérprete de Python 3 es
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/libboost_python.so.1.47.0: undefined symbol: PyClass_Type
Gracias por cualquier ayuda!
Es posible que desee considerar buscar en SWIG en lugar de Boost.Python, si puede.Requiere mucho menos código repetitivo y he conseguido que funcione con Python3 con bastante facilidad. – Sean
@Sean No estoy seguro de qué código estándar está usted hablando; mi boost/python funciona maravillosamente con solo 5 líneas de código extra. – steventrouble