私は、Python 3.2とC + +を使用して、ブーストのpythonを使用してインターフェイスしようとしています。私は最終的に2.7ライブラリを使用してコンパイルするようにしていますが、動作しますが、Python 3.2で動作させることはできません。こんにちは、ブーストのpythonとpython 3.2
ここでは、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);
}
は、そうでなければ、私はそれが2.7ライブラリを使用してコンパイルした場合、それはうまく動作しますが、私は3.2ライブラリを使用する場合、私は
libboost_python.soから未定義の参照のトンを取得します
from distutils.core import setup
from distutils.extension import Extension
setup(name="PackageName",
ext_modules=[
Extension("hello", ["testBoost.cpp"],
libraries = ["boost_python"])
])
、これはそれほど使ってPython 3.2または2.7のビルドを作成しますが、私のpython 3 interprを開くと:私はそれを動作させるためにはPythonを少し書きましたそれをインポートしようとすると、libboost_python.soからPyClass_Typeという未定義のシンボルエラーが返されます。何か案は? boost pythonはpython 3.xと互換性がありますか?
情報が有用である場合は、ここで私の未遂3.2を使用してコンパイルされます:python 3インタプリタから
$ 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
とエラーが任意の助け
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/libboost_python.so.1.47.0: undefined symbol: PyClass_Type
感謝です! C++コード
可能な場合は、Boost.PythonではなくSWIGを調べることをお勧めします。それははるかに少ない定型コードを必要とし、私はPython3でかなり簡単に動作するようになっています。 – Sean
@Seanあなたが話している定型的なコードについてはわかりません。私のboost/pythonはわずか5行の余分なコードでうまく動作します。 – steventrouble