rpath in setup.py?

Discussion in 'Python' started by Tore Ferner, Oct 2, 2003.

  1. Tore Ferner

    Tore Ferner Guest

    Hi,

    On linux:

    I'm a newbie and want to make build-versions of python 2.1.3 and
    it's modules which link against different versions of a library
    located in directories not mentioned in /etc/ld.so.conf, e.g.
    versions of expat could be:

    /opt/expatx
    /opt/expaty
    /opt/expatz

    How do I make python use -rpath against such directories, for
    example by changing setup.py? So far I've made setup.py detect
    my expat.h in /opt/expat/include, but when I use ldd on
    pyexpat.so, the libexpat located in /usr/lib is used instead of
    /opt/expatx/lib.

    I have tried to use flags like LDFLAGS="-Wl,--rpath
    -Wl,/opt/expatx/lib" and similar things during ./configure and
    make, but without luck. I am confused...

    I use Debian "stable" with gcc/g++ 3.3 and GNU ld 2.11.90.0.8
    from "testing".

    Any help/links will be greatly appreciated!!

    Regards, Tore
    Tore Ferner, Oct 2, 2003
    #1
    1. Advertising

  2. Tore Ferner wrote:
    > [...] How do I make python use -rpath against such directories, for
    > example by changing setup.py? [...]


    Here's a snippet of a setup.py from a project I'm involved in:

    ext_modules = [Extension(
    ...
    runtime_library_dirs = pypgsql_rt_dirs,
    ...
    )],

    runtime_library_dirs is a list of directories, just like library_dirs.
    And I'd think it makes sense that both refer to the same list ;)

    In other words, library_dirs ends up as -L option, whereas
    runtime_library_dirs ends up as -rpath option.

    HTH,

    -- Gerhard
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Oct 2, 2003
    #2
    1. Advertising

  3. Tore Ferner

    Tore Ferner Guest

    Gerhard Häring wrote:
    > Tore Ferner wrote:
    >
    >> [...] How do I make python use -rpath against such directories, for
    >> example by changing setup.py? [...]

    >
    >
    > Here's a snippet of a setup.py from a project I'm involved in:
    >
    > ext_modules = [Extension(
    > ...
    > runtime_library_dirs = pypgsql_rt_dirs,
    > ...
    > )],
    >
    > runtime_library_dirs is a list of directories, just like library_dirs.
    > And I'd think it makes sense that both refer to the same list ;)
    >
    > In other words, library_dirs ends up as -L option, whereas
    > runtime_library_dirs ends up as -rpath option.
    >
    > HTH,


    Thanks! But I got errors. I am not sure how to implement your suggestion.
    Is there documentation about this?

    In the examples below I place both expat and python under
    /opt/python/python2.1.3 (and with lib and include below that level).
    I changed setup.py to:

    ext_modules=[Extension('struct', ['structmodule.c'],
    runtime_library_dirs = ['/opt/python/python2.1.3/lib'] <= added
    )],


    This change generated the following error:

    $ (various flags) ./configure --prefix=/opt/python/python2.1.3
    ----[snip]
    running build_ext
    building 'struct' extension

    gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -I.
    -I/usr/local/src/python/Python-2.1.3/./Include
    -I/opt/python/python2.1.3/include -I/usr/local/include -IInclude/ -c
    /usr/local/src/python/Python-2.1.3/Modules/structmodule.c -o
    build/temp.linux-i686-2.1/structmodule.o -g -O2 -Wall -Wstrict-prototypes
    -I. -I./Include -DHAVE_CONFIG_H

    gcc -shared build/temp.linux-i686-2.1/structmodule.o
    -L/opt/python/python2.1.3/lib -L/usr/local/lib
    -R/opt/python/python2.1.3/lib -o build/lib.linux-i686-2.1/struct.so

    gcc: unrecognized option `-R/opt/python/python2.1.3/lib
    ----[snip]


    Other than that no rpath related stuff appears during compilation (as far
    as I know). Should I add pyexpat or pyexpat.c to ext_modules line somehow?

    Could it be that -R was meant for ld on the command line and not as a
    parameter for gcc to pass along to ld? (As if I were on a sun machine?)
    This is the only place where -R appears during the whole compilation.
    Should not "-Wl,--rpath -Wl,/opt/python/python2.1.3/lib" be used instead
    of "-R" for gcc on linux?


    If I add flags like:

    LIBS="-lgdbm_compat -lgdbm" LDFLAGS="-L/opt/python/python2.1.3/lib \
    -Wl,--rpath -Wl,/opt/python/python2.1.3/lib" \
    CFLAGS="-I/opt/python/python2.1.3/include \
    -L/opt/python/python2.1.3/lib \
    -Wl,--rpath -Wl,/opt/python/python2.1.3/lib \
    -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" CPPFLAGS="$CFLAGS" \
    ./configure --prefix=/opt/python/python2.1.3

    The option "-Wl,--rpath -Wl,/opt/python/python2.1.3/lib" appears only
    once during the whole compilation at this point:


    ----[snip]
    gcc -L/opt/python/python2.1.3/lib -Wl,--rpath
    -Wl,/opt/python/python2.1.3/lib -Xlinker -export-dynamic -o python \
    Modules/python.o \
    libpython2.1.a -lpthread -ldl -lgdbm_compat -lgdbm
    -lutil -lcrypt -lm
    libpython2.1.a(posixmodule.o)(.text+0x2caa): In function `posix_tmpnam':
    Modules/posixmodule.c:4218: the use of `tmpnam_r' is dangerous, better
    use `mkstemp'
    libpython2.1.a(posixmodule.o)(.text+0x2be0): In function `posix_tempnam':
    Modules/posixmodule.c:4174: the use of `tempnam' is dangerous, better use
    `mkstemp'
    PYTHONPATH= ./python ./setup.py build
    ----[snip]


    The building of the rest of the modules looks typically like this:


    ----[snip]
    building 'regex' extension
    gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -I.
    -I/usr/local/src/python/Python-2.1.3/./Include
    -I/opt/python/python2.1.3/include -I/usr/local/include -IInclude/ -c
    /usr/local/src/python/Python-2.1.3/Modules/regexmodule.c -o
    build/temp.linux-i686-2.1/regexmodule.o -
    g -O2 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H
    gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -I.
    -I/usr/local/src/python/Python-2.1.3/./Include
    -I/opt/python/python2.1.3/include -I/usr/local/include -IInclude/ -c
    /usr/local/src/python/Python-2.1.3/Modules/regexpr.c -o
    build/temp.linux-i686-2.1/regexpr.o -g -O2 -W
    all -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H
    gcc -shared build/temp.linux-i686-2.1/regexmodule.o
    build/temp.linux-i686-2.1/regexpr.o -L/opt/python/python2.1.3/lib
    -L/usr/local/lib -o build/lib.linux-i686-2.1/regex.so
    ----[snip]



    I have also tried to edit the file Modules/Setup, uncommenting pyexpat
    and adding -Xlinker options:

    pyexpat pyexpat.c -I/opt/python/python2.1.3/include \
    -L/opt/python/python2.1.3/lib -lexpat -Xlinker --rpath -Xlinker \
    /opt/python/python2.1.3/lib

    (The line is not diveded up in the source.)

    That resulted in errors because the header file xmlparse.h couldn't be
    found. I do not know if this file is supposed to come from expat, libxml
    or what. I have expat version 1.95.6 (with added definition for
    XML_Status) and there I have found I file called xmlparse.c but not
    xmlparse.h - yet.

    Any ideas?

    Regards, Tore
    Tore Ferner, Oct 3, 2003
    #3
  4. Tore Ferner

    Marc Recht Guest

    > ext_modules=[Extension('struct', ['structmodule.c'],
    > runtime_library_dirs = ['/opt/python/python2.1.3/lib'] <= added
    > )],


    Did you try the following already?
    ....
    extra_link_args = ['-Wl,-R/opt/python/python2.1.3/lib']
    ....

    Marc
    Marc Recht, Oct 3, 2003
    #4
  5. Tore Ferner

    Tore Ferner Guest

    Marc Recht wrote:
    >> ext_modules=[Extension('struct', ['structmodule.c'],
    >> runtime_library_dirs = ['/opt/python/python2.1.3/lib'] <= added
    >> )],

    >
    >
    > Did you try the following already?
    > ...
    > extra_link_args = ['-Wl,-R/opt/python/python2.1.3/lib']
    > ...


    Yes, that solved the problem. I found the documentation and when I use
    this and add an Extension for pyexpat in exts.append, it works. Similar
    changes in other 3. party modules also work as it should.

    Happy me, Tore
    Tore Ferner, Oct 6, 2003
    #5
    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. Andrew Clancy
    Replies:
    0
    Views:
    3,273
    Andrew Clancy
    Jul 18, 2003
  2. Microsoft
    Replies:
    0
    Views:
    2,939
    Microsoft
    Sep 4, 2003
  3. Mark Harrison

    --enable-shared, how do i set the rpath?

    Mark Harrison, Nov 27, 2006, in forum: Python
    Replies:
    2
    Views:
    311
    Robert Kern
    Nov 27, 2006
  4. Chris Shenton
    Replies:
    1
    Views:
    1,444
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Aug 24, 2007
  5. Intransition

    [ANN] Ruby Setup 5 (setup.rb)

    Intransition, Jan 13, 2010, in forum: Ruby
    Replies:
    0
    Views:
    415
    Intransition
    Jan 13, 2010
Loading...

Share This Page