[C++-sig] Using boost.python with Makefile (no bjam)

2010-10-06 Thread Philipp Münzel
Hi everyone,

thanks to hints on this list I've now got a working build of boost.python.

I built the hello world exmaple (using the jam-file) and ran the
testsuite with success.

Now I want to get used to boost.python by exporting a few functions of a
C++ lib I'm working on. This lib uses make as buildtool. Therefore I
want to know how to setup a Makefile for boost.python.

To start from ground up, I just took the example source code from
libs/python/example/tutorial/hello.cpp and tried to compile and link it
as a shared library. Unfortunately, there remain undefined symbols,
which is why it cannot be loaded as python module.

My boost installation is under /usr/local and is built in system layout
as static libraries (libboost_x.a).

$ 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 
#include 

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" -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 "", line 1, in 
ImportError: ./libhello.so: undefined symbol:
_ZNK5boost6python7objects21py_function_impl_base9max_arityEv

So what is the big magic of bjam that when bjam links libboost_python.a
I get no undefined symbols, but when i do it "by hand" i get these?

Regards,
Philipp
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Using boost.python with Makefile (no bjam)

2010-10-06 Thread Philipp Münzel
Oh crap, the command that links is of course:

$ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python
-o libhello.so hello.o

But I get the undefined symbols nevertheless:
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 _Znwj@@GLIBCXX_3.4
 U __cxa_atexit@@GLIBC_2.1.3
 w __cxa_finalize@@GLIBC_2.1.3
 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
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Using boost.python with Makefile (no bjam)

2010-10-06 Thread Charles Solar
You need to link with libpython as well.  libpython should resolve these.

On Wed, Oct 6, 2010 at 5:43 AM, Philipp Münzel  wrote:
> Oh crap, the command that links is of course:
>
> $ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python
> -o libhello.so hello.o
>
> But I get the undefined symbols nevertheless:
> 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 _Znwj@@GLIBCXX_3.4
>         U __cxa_atexit@@GLIBC_2.1.3
>         w __cxa_finalize@@GLIBC_2.1.3
>         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
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Using boost.python with Makefile (no bjam)

2010-10-06 Thread Philipp Münzel
I added -lpython2.6 to the linker command, but I didn't change anything.
Obviously, the missing symbols are boost symbols and not python symbols,
since their names
_ZN5boost6python6detail11init_moduleEPKcPFvvE
clearly refer boost.

I built boost_python with the following command:

sudo ./bjam install -q --layout=system --with-python toolset=gcc
variant=release link=static threading=multi runtime-link=static

What is missing here?

Philipp


On 10/06/2010 03:30 PM, Charles Solar wrote:
> You need to link with libpython as well.  libpython should resolve these.
> 
> On Wed, Oct 6, 2010 at 5:43 AM, Philipp Münzel  wrote:
>> Oh crap, the command that links is of course:
>>
>> $ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python
>> -o libhello.so hello.o
>>
>> But I get the undefined symbols nevertheless:
>> 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 _Znwj@@GLIBCXX_3.4
>> U __cxa_atexit@@GLIBC_2.1.3
>> w __cxa_finalize@@GLIBC_2.1.3
>> 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
>> ___
>> Cplusplus-sig mailing list
>> [email protected]
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig