bjam `无法找到名为'libboost_python'的文件或目标`

1 投票
3 回答
3859 浏览
提问于 2025-04-16 18:10

我在配置和安装Boost.Python时漏掉了什么呢?

我正在尝试编译一个教程示例,但出现了找不到libboost_python的错误。

cd /usr/share/doc/libboost1.42-doc/examples/libs/python/example/tutorial
bjam
error: Unable to find file or target named
error:     'libboost_python'
error: referred from project at
error:     '.'

但是这个库是存在的,ldconfig.real已经运行过了:

/usr/lib/libboost_python.a -> libboost_python-py27.a
/usr/lib/libboost_python-mt-py26.a -> libboost_python-py26.a
/usr/lib/libboost_python-mt-py26.so -> libboost_python-py26.so.1.42.0
/usr/lib/libboost_python-mt-py27.a -> libboost_python-py27.a
/usr/lib/libboost_python-mt-py27.so -> libboost_python-py27.so.1.42.0
/usr/lib/libboost_python-py26.a
/usr/lib/libboost_python-py26.so -> libboost_python-py26.so.1.42.0
/usr/lib/libboost_python-py26.so.1.42.0
/usr/lib/libboost_python-py27.a
/usr/lib/libboost_python-py27.so -> libboost_python-py27.so.1.42.0
/usr/lib/libboost_python-py27.so.1.42.0
/usr/lib/libboost_python.so -> libboost_python-py27.so

我使用的是Ubuntu 11.04的默认libboost包。

我的user-config.jam

using python : 2.7 ;

3 个回答

0

你可以有一个网站配置文件,里面可以写一些类似下面的内容;

using boost : 1.48 : <include>/usr/include/boost-1_48 <library>/usr/lib ;

(你需要< library >那部分,不太清楚为什么)

然后你可以做一些这样的事情。

project foo 
        : <library>/boost//python

这样做从长远来看会更简单,因为你总有一天会需要更改boost的版本。

1

我在使用ubuntu 12.04的时候遇到过类似的问题,当时我安装了所有的boost库。最后我在这里找到了解决办法:

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命令

make

5.) 准备好了。在python中使用:

import hello_ext
print hello_ext.greet()
0

我还是不太确定这是不是正确的方法,看起来有点像小技巧,但这样做确实有帮助:

Jamroot 文件中,把

project
  : requirements <library>libboost_python ;

替换成

project
  : requirements <library>/usr/lib/libboost_python.so ;

撰写回答