rpath in setup.py?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tore Ferner

    rpath in setup.py?

    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

  • Gerhard Häring

    #2
    Re: rpath in setup.py?

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

    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

    Comment

    • Tore Ferner

      #3
      Re: rpath in setup.py?

      Gerhard Häring wrote:[color=blue]
      > Tore Ferner wrote:
      >[color=green]
      >> [...] How do I make python use -rpath against such directories, for
      >> example by changing setup.py? [...][/color]
      >
      >
      > 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,[/color]

      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('stru ct', ['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_S OURCE -D_FILE_OFFSET_B ITS=64" CPPFLAGS="$CFLA GS" \
      ./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:4 218: the use of `tmpnam_r' is dangerous, better
      use `mkstemp'
      libpython2.1.a( posixmodule.o)( .text+0x2be0): In function `posix_tempnam' :
      Modules/posixmodule.c:4 174: 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

      Comment

      • Marc Recht

        #4
        Re: rpath in setup.py?

        > ext_modules=[Extension('stru ct', ['structmodule.c '],[color=blue]
        > runtime_library _dirs = ['/opt/python/python2.1.3/lib'] <= added
        > )],[/color]

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

        Marc

        Comment

        • Tore Ferner

          #5
          Re: rpath in setup.py?

          Marc Recht wrote:[color=blue][color=green]
          >> ext_modules=[Extension('stru ct', ['structmodule.c '],
          >> runtime_library _dirs = ['/opt/python/python2.1.3/lib'] <= added
          >> )],[/color]
          >
          >
          > Did you try the following already?
          > ...
          > extra_link_args = ['-Wl,-R/opt/python/python2.1.3/lib']
          > ...[/color]

          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

          Comment

          Working...