Ubuntu 12.04上的Boost :: python示例

hmh*_*mmm 2 python boost ubuntu-12.04

我正在尝试在ubuntu 12.04上构建boost:python示例.我从包管理器(而不是源代码)安装了库.我之前也没有使用过boost,并且没有为此设置任何环境变量(BOOST_BUILD_PATH未设置).我收到此错误:

/usr/share/doc/libboost1.46-doc/examples/libs/python/example/tutorial$ bjam --debug-configuration
notice: found boost-build.jam at /usr/share/doc/libboost1.46-doc/examples/libs/python/example/boost-build.jam
Unable to load Boost.Build: could not find build system.
---------------------------------------------------------
/usr/share/doc/libboost1.46-doc/examples/libs/python/example/boost-build.jam attempted to load the build system by invoking
'boost-build ../../../tools/build/v2 ;'
but we were unable to find "bootstrap.jam" in the specified directory
or in BOOST_BUILD_PATH (searching /usr/share/doc/libboost1.46-doc/examples/libs/python/example/../../../tools/build/v2, /usr/share/boost-build).
Please consult the documentation at 'http://www.boost.org'.
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我应该在哪里指向BOOST_BUILD_PATH?

小智 6

我有同样的问题,我在这里找到了解决方案:

http://jayrambhia.wordpress.com/2012/06/25/configuring-boostpython-and-hello-boost/

事实证明,你根本不需要使用bjam.makefile就足够了.我将在此处重复上述链接中的解决方案:

1.)安装libboost-python包

2.)创建一个名为'hello_ext.c'的hello world源文件:

char const* greet()
{
    return "hello, world";
}

#include<boost/python.hpp>
BOOST_PYTHON_MODULE(hello_ext)
{
   using namespace boost::python;
   def("greet",greet);
}
Run Code Online (Sandbox Code Playgroud)

3.)创建一个makefile:

PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
# compile mesh classes
TARGET = hello_ext
$(TARGET).so: $(TARGET).o
    g++ -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python -L/usr   /lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so
$(TARGET).o: $(TARGET).c
    g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).c
Run Code Online (Sandbox Code Playgroud)

4.)制作

make
Run Code Online (Sandbox Code Playgroud)

5.)准备使用.在python中:

import hello_ext
print hello_ext.greet()
Run Code Online (Sandbox Code Playgroud)

编辑包含选项卡.

  • 必须在makefile中有那些缩进....在以g ++开头的两行之前放一个标签 (2认同)