[C++-sig] Re: Boost::Python for C code -> Segmentation fault
Mario Palomo
mario-p at iname.com
Wed Jul 28 13:18:16 CEST 2004
Thanks a lot!!
Using Linux (Debian Sid) Boost::Python packages and using g++ to link works for
me too.
I've changed the original file to use 'int name' instead of 'char *name':
FILE: hello.cpp
=================== BEGIN =======================
#include <stdio.h>
//typedef
struct user {
int name;
int number;
};//user;
void greet(user *u)
{
printf("Hello %d, your number is %d.\n", u->name, u->number);
}
/*-------------------------------------------- */
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/class.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
class_<user>("user")
.def_readwrite("name", &user::name)
.def_readwrite("number", &user::number)
;
def("greet", greet);
}
==================== END ========================
$ g++ -c hello.cpp -Wall -I/usr/include/python2.3
$ g++ -shared -o hello.so hello.o -lboost_python
$ python
Python 2.3.4 (#2, Jul 5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
>>> u = hello.user()
>>> u.number=10
>>> u.name=20
>>> hello.greet(u)
Hello 20, your number is 10.
>>>
$
Using 'ldd' I get the segfault (even if I use 'int name').
Then, should I use always g++ for linking C++ code?
I've been using 'ldd' for years... :-)
Ralf W. Grosse-Kunstleve wrote:
> --- sashan <sashang at ihug.co.nz> wrote:
>
>
>>>There is no segfault under Red Hat 8 when using these commands:
>>>
>>>g++ -fPIC -O0 -I/net/worm/scratch1/rwgk/dist/boost -I/usr/include/python2.2
>>
>>-c
>>
>>>-o segfault.os segfault.cpp
>>>g++ -shared -o segfault.so segfault.os -Llibtbx -lboost_python -lm
>>>
>>
>>Thanks for that. The following works for me:
>>
>>g++ -g -I/usr/include/python2.3 -c -osegfault.o segfault.cpp
>>g++ -shared -osegfault.so segfault.o -lboost_python
>>
>>whereas if I used ld to do the linking:
>>
>>ld -shared -osegfault.so segfault.o -lboost_python
>>
>>a segfault occurs. I don't know why.
>
>
> Probably because the g++ front-end implicitly adds different runtime libraries.
> Ralf
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.
> http://promotions.yahoo.com/new_mail
More information about the Cplusplus-sig
mailing list