python - Ubuntu 12.04 上的 Boost::python 示例

标签 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'.

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

最佳答案

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

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);
}

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

4.) 制作

make

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

import hello_ext
print hello_ext.greet()

编辑以包含一个选项卡。

关于python - Ubuntu 12.04 上的 Boost::python 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13317311/

相关文章:

python - django 翻译模板 {% trans "something"%}

c++错误访问boost fusion 对中的字段类型

c++ - 跨平台MultiByteToWideChar

python - Matplotlib 2 字体不一致

python - PySpark:将不同的窗口大小应用于 pyspark 中的数据帧

python - jpype._jclass.NoClassDefFoundError : edu/stanford/nlp/python/SUTimeWrapper

c++ - boost::asio 多线程异步接受阻塞读/写服务器

ubuntu - Ubuntu 12.04 LTS 上的 Hadoop 单节点集群安装在哪里?

用于检索所需行的 Linux 命令

postgresql 服务器不听