Ubuntu 12.04上的Boost::python示例

Ubuntu 12.04上的Boost::python示例,python,boost,ubuntu-12.04,Python,Boost,Ubuntu 12.04,我试图在ubuntu 12.04上构建boost:python示例。 我从PackageManager(而不是源代码)安装了这些库。 我以前也没有使用过boost,也没有为此设置任何环境变量(boost\u BUILD\u PATH未设置)。 我得到这个错误: /usr/share/doc/libboost1.46-doc/examples/libs/python/example/tutorial$ bjam --debug-configuration notice: found boost-b

我试图在ubuntu 12.04上构建boost:python示例。 我从PackageManager(而不是源代码)安装了这些库。 我以前也没有使用过boost,也没有为此设置任何环境变量(boost\u BUILD\u 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'.
我怎样才能修好它?
我应该将BOOST\u BUILD\u路径指向何处?

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

事实证明,您根本不需要使用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);
}
4)制造

5.)随时可用。在python中:

import hello_ext
print hello_ext.greet()


编辑为包含一个选项卡。

我已经将它们从我的Lucid box上的源代码解压到~/boost\u 1\u 49\u 0中,在
~/boost\u 1\u 49\u 0/tools/build/v2中有bootstrap.jam。有什么特别的原因让你不想抓取tarball并将其解包?根据我的经验,将package manager安装的库与tarball混合会导致混乱,因此我希望避免从tarball安装找到bootstrap.jam/usr/share/boost build/kernel/bootstrap.jam这是正确的bootstrap.jam吗。你也在12.04从tarball安装了吗?我还在10.04上,所以我不能说关于12.04的任何事情。所以我的情况很简单:我需要一个比存储库中可用版本更新的boost版本,所以---下载tarball,解包,然后在makefile中添加这些缩进…在两行前面都添加一个标签,以g++开始,这是一个很好的答案。让您想知道,当一个简单的Makefile将演示如何构建它时,为什么boostpython教程会带您走上一条处理Jamroot、bjam、user-config.jam和其他事情的道路。一个小问题是hello_ext.c在Boost教程中是一个.cpp文件,因此需要$(TARGET).cpp。这完全建立在15.04 vivid的基础上。另外,在
-L/usr
/lib/python$python…
之间有一个空格需要删除。运行make命令时会显示以下错误:g++-shared-Wl,--导出动态hello_ext.o-L/usr/lib-lboost_python-L/usr/lib/python2.7/config-lpython2.7-o hello_ext.so g++:错误:/lib/python2.7/config:没有这样的文件或目录MakeFile:9:目标“hello_ext.so”的制作方法失败:**[hello_ext.so]错误1
make
import hello_ext
print hello_ext.greet()