Build of extension module depending on external lib fails on Solaris 10

Discussion in 'Python' started by Eric Brunel, Nov 21, 2008.

  1. Eric Brunel

    Eric Brunel Guest

    Hello all,

    I've got a brand new Solaris 10 computer and I'm trying to build Python
    and extension modules for it. The Python build didn't have any problem and
    I have a working Python interpreter. But I can't succeed to build
    extension modules depending on external libraries: The compilation works,
    and object files are produced, but the link always fails.

    Here is an example of a failing setup.py file:
    ----------------------------------------
    from distutils.core import setup, Extension

    setup(
    name='spam',
    version='1.0',
    ext_modules=[
    Extension('spam', ['spam.c'], library_dirs=['.'], libraries=['spam'])
    ]
    )
    ----------------------------------------

    The 'spam' external module is basically a copy of the one appearing in the
    'Extending and Embedding' manual, except it also contains a call to a
    function in libspam.a, which just does a printf.

    Here is the result of the command 'python setup.py build':
    ----------------------------------------
    running build
    running build_ext
    building 'spam' extension
    gcc -shared build/temp.solaris-2.10-i86pc-2.6/spam.o -L. -lspam -o
    build/lib.solaris-2.10-i86pc-2.6/spam.so
    Text relocation remains referenced
    against symbol offset in file
    <unknown> 0xa ./libspam.a(spamlib.o)
    printf 0xf ./libspam.a(spamlib.o)
    ld: fatal: relocations remain against allocatable but non-writable sections
    collect2: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1
    ----------------------------------------

    It seems the problem lies in the order on which the object files and
    libraries appear in the link command line, because if I run the same
    command with the libraries before the object files:
    gcc -shared -L. -lspam build/temp.solaris-2.10-i86pc-2.6/spam.o -o
    build/lib.solaris-2.10-i86pc-2.6/spam.so
    the link works without problem and a working shared object file is
    produced.

    Did anybody have this kind of problem? Is it a bug, or am I doing
    something wrong? And is there a workaround?

    Thanks in advance.
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
    Eric Brunel, Nov 21, 2008
    #1
    1. Advertising

  2. Re: Build of extension module depending on external lib fails onSolaris 10

    On Nov 22, 2:07 am, "Eric Brunel" <> wrote:
    > Hello all,
    >
    > I've got a brand new Solaris 10 computer and I'm trying to build Python  
    > and extension modules for it. The Python build didn't have any problem and  
    > I have a working Python interpreter. But I can't succeed to build  
    > extension modules depending on external libraries: The compilation works,  
    > and object files are produced, but the link always fails.
    >
    > Here is an example of a failing setup.py file:
    > ----------------------------------------
    >  from distutils.core import setup, Extension
    >
    > setup(
    >    name='spam',
    >    version='1.0',
    >    ext_modules=[
    >      Extension('spam', ['spam.c'], library_dirs=['.'], libraries=['spam'])
    >    ]
    > )
    > ----------------------------------------
    >
    > The 'spam' external module is basically a copy of the one appearing in the  
    > 'Extending and Embedding' manual, except it also contains a call to a  
    > function in libspam.a, which just does a printf.
    >
    > Here is the result of the command 'python setup.py build':
    > ----------------------------------------
    > running build
    > running build_ext
    > building 'spam' extension
    > gcc -shared build/temp.solaris-2.10-i86pc-2.6/spam.o -L. -lspam -o  
    > build/lib.solaris-2.10-i86pc-2.6/spam.so
    > Text relocation remains                         referenced
    >      against symbol                  offset      in file
    > <unknown>                           0xa         ./libspam.a(spamlib.o)
    > printf                              0xf         ./libspam.a(spamlib.o)
    > ld: fatal: relocations remain against allocatable but non-writable sections
    > collect2: ld returned 1 exit status
    > error: command 'gcc' failed with exit status 1
    > ----------------------------------------
    >
    > It seems the problem lies in the order on which the object files and  
    > libraries appear in the link command line, because if I run the same  
    > command with the libraries before the object files:
    > gcc -shared -L. -lspam build/temp.solaris-2.10-i86pc-2.6/spam.o -o  
    > build/lib.solaris-2.10-i86pc-2.6/spam.so
    > the link works without problem and a working shared object file is  
    > produced.
    >
    > Did anybody have this kind of problem? Is it a bug, or am I doing  
    > something wrong? And is there a workaround?


    See workaround in:

    http://code.google.com/p/modwsgi/wiki/InstallationOnSolaris

    Different package, but same issue, so use same workaround.

    Graham

    Graham
    Graham Dumpleton, Nov 21, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Williams
    Replies:
    2
    Views:
    370
    Dieter Maurer
    May 2, 2004
  2. Christopher
    Replies:
    4
    Views:
    307
    Christopher
    Nov 1, 2007
  3. Iñaki Baz Castillo
    Replies:
    1
    Views:
    145
    Iñaki Baz Castillo
    Feb 28, 2011
  4. Replies:
    2
    Views:
    74
  5. Replies:
    0
    Views:
    99
Loading...

Share This Page