ブースト:1.60.0
パイソン:3.5.0.1
(アナコンダから)boost_python - (少数)未定義の参照
サンプルコード: g++ -std=c++11 test.cpp -o test.o -I/home/user/anaconda3/pkgs/python-3.5.1-0/include/python3.5m/ -L/home/user/anaconda3/pkgs/python-3.5.1-0/lib/python3.5/config-3.5m -lpython3.5m -pthread -lutil -ldl -lboost_python3
出力:としてコンパイル
#include <iostream>
#include <boost/python.hpp>
#include <Python.h>
namespace py = boost::python;
int main()
{
// Must be called before any boost::python functions
Py_Initialize();
// import the main module
py::object main_module = py::import("__main__");
// load the dictionary object out of the main module
py::object main_namespace = main_module.attr("__dict__");
// run simple code within the main namespace using the boost::python::exec
// function
py::exec("print ('Hello, world')", main_namespace);
// any valid Python will execute
py::exec("print ('Hello, world')[3:5]", main_namespace);
}
:
//usr/local/lib/libboost_python3.so: undefined reference to `PyString_AsString'
//usr/local/lib/libboost_python3.so: undefined reference to `PyInt_Type'
//usr/local/lib/libboost_python3.so: undefined reference to `PyString_FromStringAndSize'
//usr/local/lib/libboost_python3.so: undefined reference to `PyString_FromString'
//usr/local/lib/libboost_python3.so: undefined reference to `PyString_FromFormat'
//usr/local/lib/libboost_python3.so: undefined reference to `PyInt_FromLong'
//usr/local/lib/libboost_python3.so: undefined reference to `PyInt_AsLong'
//usr/local/lib/libboost_python3.so: undefined reference to `PyString_Type'
これまでは、他のリンカーエラーも出ていましたが、Pythonの2.7バージョンにリンクしていました。私はboost_python
を3.5バージョンで作った。
私は、これらの機能が実際には3.5にはないことを理解しています。彼らがどこで使われているのか分かりません。逆に
は、PLの下方見つける:
:~/$ nm /usr/local/lib/libboost_python3.so |grep "PyString"
U PyString_AsString
U PyString_FromFormat
U PyString_FromString
U PyString_FromStringAndSize
U PyString_Type
:~/$ nm /usr/local/lib/libboost_python3.so |grep "PyInt"
U PyInt_AsLong
U PyInt_FromLong
U PyInt_Type
は、どのように私は単に '先に行く' ことができますか?
私は実際には私は私はこれらを呼び出すされませんが動作しませんので、C++ファイル内でこれらの関数を定義しようとしました。私はこれが1つの陽気な方法だったことを知っている...しかし、あなたにアイデアを与えるために、私は '上に移動したい、私はそれを言いました。
はそれを試してみましたが、同じ出力を提供します – Adorn