Phi*_*ipp 8 makefile bjam boost-python
我只是想编译boost.python的"hello world"示例而不使用所有的bjam魔法.我的boost.python安装工作正常,我用bjam成功构建了示例并通过了测试套件.
现在,对于我的项目,我需要在普通的Make环境中使用所有这些东西.我不想移植到另一个构建工具.
所以我的天真方法当然只是将包含路径指向正确的标题并链接到正确的库.我将boost python构建为system-layout,static,runtime-static,这意味着它只是一个驻留在/ usr/local/lib中的libboost_python.a.
不幸的是,我在生成的.so库中得到了未解析的外部符号.
这是我尝试从libs/python/example/tutorial/hello.cpp构建示例:
$ cat hello.cpp
// Copyright Joel de Guzman 2002-2004. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// Hello World Example from the tutorial
// [Joel de Guzman 10/9/2002]
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
$ g++ -I/usr/local/include -I/usr/include/python -fpic -c -o hello.o
hello.cpp
$ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python -fpic -o libhello.so hello.o
$ nm -u libhello.so
U PyString_Type
w _Jv_RegisterClasses
U _Py_NoneStruct
U _Unwind_Resume@@GCC_3.0
U _ZN5boost6python6detail11init_moduleEPKcPFvvE
U _ZN5boost6python6detail12gcc_demangleEPKc
U
_ZN5boost6python6detail17scope_setattr_docEPKcRKNS0_3api6objectES3_
U
_ZN5boost6python7objects15function_objectERKNS1_11py_functionE
U _ZN5boost6python7objects21py_function_impl_baseD2Ev
U _ZN5boost6python9converter19do_return_to_pythonEPKc
U _ZN5boost6python9converter8registry5queryENS0_9type_infoE
U
_ZNK5boost6python7objects21py_function_impl_base9max_arityEv
U
_ZNK5boost6python9converter12registration25expected_from_python_typeEv
U _ZTIN5boost6python7objects21py_function_impl_baseE
U _ZTIPKc@@CXXABI_1.3
U _ZTIc@@CXXABI_1.3
U _ZTVN10__cxxabiv120__si_class_type_infoE@@CXXABI_1.3
U _ZTVN5boost6python7objects21py_function_impl_baseE
U _ZdlPv@@GLIBCXX_3.4
U _Znwm@@GLIBCXX_3.4
U __cxa_atexit@@GLIBC_2.2.5
w __cxa_finalize@@GLIBC_2.2.5
U __cxa_guard_abort@@CXXABI_1.3
U __cxa_guard_acquire@@CXXABI_1.3
U __cxa_guard_release@@CXXABI_1.3
w __gmon_start__
U __gxx_personality_v0@@CXXABI_1.3
$ python
>>> import libhello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./libhello.so: undefined symbol:
_ZNK5boost6python7objects21py_function_impl_base9max_arityEv
Run Code Online (Sandbox Code Playgroud)
那么当bjam链接libboost_python.a时,bjam的巨大魔力是什么?我没有得到任何未定义的符号,但是当我"手工"这样做时,我得到了这些?
好吧,我是愚蠢的.要链接一个必须将库之前的对象与符号放在一起.转身
g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python -fpic -o libhello.so hello.o
Run Code Online (Sandbox Code Playgroud)
成
g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib hello.o -lboost_python -fpic -o libhello.so
Run Code Online (Sandbox Code Playgroud)
在用cxxflags = -fPIC重新编译boost.python之后,给了我预期的结果.
| 归档时间: |
|
| 查看次数: |
7814 次 |
| 最近记录: |