Boost Python出现“没有这样的文件或目录”错误

23
我已经从Ubuntu 9.04的仓库安装了Boost Python。我已经成功地运行了教程中的使用Boost构建简单程序,所以我知道Boost Python已经安装在我的系统上。
然而,下面的程序返回一个错误:
#include <string>

namespace { // Avoid cluttering the global namespace.

  // A couple of simple C++ functions that we want to expose to Python.
  std::string greet() { return "hello, world"; }
  int square(int number) { return number * number; }
}
#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(getting_started1)
{
    // Add regular functions to the module.
    def("greet", greet);
    def("square", square);
}

我尝试执行以下两个步骤中的第一个步骤来创建共享库:

g++ -c -fPIC hello.cpp -o hello.o
g++ -shared -Wl,-soname,libhello.so -o libhello.so  hello.o

(这些是正确的命令吗?)

下面是完整的错误输出:

In file included from /usr/include/boost/python/detail/prefix.hpp:13,
             from /usr/include/boost/python/args.hpp:8,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/detail/wrap_python.hpp:50:23: error: pyconfig.h: No such file or directory
/usr/include/boost/python/detail/wrap_python.hpp:75:24: error: patchlevel.h: No such file or directory
/usr/include/boost/python/detail/wrap_python.hpp:78:2: error: #error Python 2.2 or higher is required for this version of Boost.Python.
/usr/include/boost/python/detail/wrap_python.hpp:142:21: error: Python.h: No such file or directory
In file included from /usr/include/boost/python/cast.hpp:13,
             from /usr/include/boost/python/handle.hpp:10,
             from /usr/include/boost/python/args_fwd.hpp:10,
             from /usr/include/boost/python/args.hpp:10,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/base_type_traits.hpp:24: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/base_type_traits.hpp:24: error: template argument 1 is invalid
/usr/include/boost/python/base_type_traits.hpp:30: error: ‘PyTypeObject’ was not declared in this scope
/usr/include/boost/python/base_type_traits.hpp:30: error: template argument 1 is invalid
/usr/include/boost/python/base_type_traits.hpp:36: error: ‘PyMethodObject’ was not declared in this scope
/usr/include/boost/python/base_type_traits.hpp:36: error: template argument 1 is invalid
In file included from /usr/include/boost/python/handle.hpp:11,
             from /usr/include/boost/python/args_fwd.hpp:10,
             from /usr/include/boost/python/args.hpp:10,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/errors.hpp:51: error: expected constructor, destructor, or type conversion before ‘*’ token
In file included from /usr/include/boost/python/handle.hpp:13,
             from /usr/include/boost/python/args_fwd.hpp:10,
             from /usr/include/boost/python/args.hpp:10,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/handle_fwd.hpp:12: error: expected type-specifier before ‘PyObject’
/usr/include/boost/python/handle_fwd.hpp:12: error: expected ‘>’ before ‘PyObject’
In file included from /usr/include/boost/python/handle.hpp:14,
             from /usr/include/boost/python/args_fwd.hpp:10,
             from /usr/include/boost/python/args.hpp:10,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/refcount.hpp: In function ‘T* boost::python::incref(T*)’:
/usr/include/boost/python/refcount.hpp:16: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/refcount.hpp: In function ‘T* boost::python::xincref(T*)’:
/usr/include/boost/python/refcount.hpp:23: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/refcount.hpp: In function ‘void boost::python::decref(T*)’:
/usr/include/boost/python/refcount.hpp:30: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/refcount.hpp: In function ‘void boost::python::xdecref(T*)’:
/usr/include/boost/python/refcount.hpp:36: error: ‘PyObject’ was not declared in this scope
In file included from /usr/include/boost/python/args_fwd.hpp:10,
             from /usr/include/boost/python/args.hpp:10,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/handle.hpp: In constructor ‘boost::python::handle<T>::handle(boost::python::detail::borrowed_reference_t*)’:
/usr/include/boost/python/handle.hpp:130: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/handle.hpp:130: error: expected primary-expression before ‘)’ token
/usr/include/boost/python/handle.hpp: At global scope:
/usr/include/boost/python/handle.hpp:157: error: ‘PyTypeObject’ was not declared in this scope
/usr/include/boost/python/handle.hpp:157: error: template argument 1 is invalid
/usr/include/boost/python/handle.hpp:157: error: invalid type in declaration before ‘;’ token
/usr/include/boost/python/handle.hpp:256: error: expected initializer before ‘*’ token
In file included from /usr/include/boost/python/args.hpp:10,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/args_fwd.hpp:26: error: template argument 1 is invalid
In file included from /usr/include/boost/python/object/pointer_holder.hpp:14,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/instance_holder.hpp:34: error: ‘PyObject’ has not been declared
/usr/include/boost/python/instance_holder.hpp:41: error: expected ‘;’ before ‘(’ token
/usr/include/boost/python/instance_holder.hpp:45: error: ‘PyObject’ has not been declared
In file included from /usr/include/boost/python/object/pointer_holder.hpp:21,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/detail/wrapper_base.hpp:21: error: expected initializer before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:23: error: expected initializer before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:30: error: expected initializer before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:34: error: expected initializer before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:43: error: ‘PyObject’ has not been declared
/usr/include/boost/python/detail/wrapper_base.hpp:44: error: ‘PyObject’ is neither function nor member function; cannot be declared friend
/usr/include/boost/python/detail/wrapper_base.hpp:44: error: expected ‘;’ before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:49: error: ‘PyTypeObject’ has not been declared
/usr/include/boost/python/detail/wrapper_base.hpp:55: error: expected ‘;’ before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp: In constructor ‘boost::python::detail::wrapper_base::wrapper_base()’:
/usr/include/boost/python/detail/wrapper_base.hpp:46: error: class ‘boost::python::detail::wrapper_base’ does not have any field named ‘m_self’
/usr/include/boost/python/detail/wrapper_base.hpp: At global scope:
/usr/include/boost/python/detail/wrapper_base.hpp:61: error: expected initializer before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:71: error: expected initializer before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:77: error: variable or field ‘initialize_wrapper’ declared void
/usr/include/boost/python/detail/wrapper_base.hpp:77: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/detail/wrapper_base.hpp:77: error: ‘self’ was not declared in this scope
/usr/include/boost/python/detail/wrapper_base.hpp:77: error: expected primary-expression before ‘*’ token
/usr/include/boost/python/detail/wrapper_base.hpp:77: error: ‘w’ was not declared in this scope
/usr/include/boost/python/detail/wrapper_base.hpp:82: error: variable or field ‘initialize_wrapper’ declared void
/usr/include/boost/python/detail/wrapper_base.hpp:82: error: ‘PyObject’ was not declared in this scope
/usr/include/boost/python/detail/wrapper_base.hpp:82: error: expected primary-expression before ‘,’ token
/usr/include/boost/python/detail/wrapper_base.hpp:82: error: expected primary-expression before ‘...’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:57,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:62,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:67,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:72,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:77,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:82,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:87,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:92,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:97,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:102,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:107,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:112,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:117,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:122,
             from /usr/include/boost/python/object/pointer_holder.hpp:63,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:176: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:57,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:62,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:67,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:72,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:77,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:82,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:87,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:92,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
             from /usr/include/boost/python.hpp:11,
             from first.cpp:9:
/usr/include/boost/python/object/pointer_holder.hpp:199: error: expected `)' before ‘*’ token
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:97,
             from /usr/include/boost/python/object/pointer_holder.hpp:99,
             from /usr/include/boost/python/to_python_indirect.hpp:10,
             from /usr/include/boost/python/converter/arg_to_python.hpp:10,
             from /usr/include/boost/python/call.hpp:15,
             from /usr/include/boost/python/object_core.hpp:12,
             from /usr/include/boost/python/args.hpp:25,
4个回答

31

在代码中添加 #include <Python.h> 并且使用 -I/usr/include/python2.6 或者你所使用的 Python 版本进行编译。

不要忘记链接使用 -lpython2.6 -lboost_python


4
我遇到了同样的问题,这个方法解决了我的问题。如果有人也使用Debian系统,注意squeeze版本有一个python-dev和python2.6-dev软件包(我花了5分钟左右来寻找解决方法)。 - user118861
在我的情况下,我遇到了同样的问题,它找不到pyconfig.h,所以我执行了'g++ -shared -c -o greet.so -fPIC greet.cpp -lpython2.7 -lboostpython -I/usr/local/include/python2.7'。 - Chan Kim

17

虽然有些晚了,但是这里是我的回答:

确保你已经安装了libboost-python-dev库:

sudo apt-get install libboost-python-dev

这对我起了作用。


9

看起来你缺少Python头文件(Python.h等)。通过操作系统包管理器确保安装了适用于你的Python版本的-devel或-dev包。这应该提供头文件...

[编辑:注意到你在Ubuntu上,尝试sudo aptitude install python-dev]


sudo aptitude install python-dev 帮了我大忙!非常感谢! - Temak

3
通过逐个执行命令来构建大型程序很快就会变得非常复杂。您可以使用类似于CMake的构建系统来查找依赖项并为您整理编译器命令。
将CMake与boost python项目一起使用的最小CMakeLists.txt如下所示:
project (MyProject)
cmake_minimum_required(VERSION 2.8)

find_package(PythonLibs)
include_directories (${PYTHON_INCLUDE_DIRS})

find_package(Boost 1.45.0 COMPONENTS python)
include_directories (${Boost_INCLUDE_DIRS})


add_library (
    mylibinterface SHARED  
    mylib.cpp
)

target_link_libraries (mylibinterface
    boost_python
    ${PYTHON_LIBRARIES}
    ${Boost_LIBRARIES}
)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接