rpath in setup.py?

Tore Ferner torfer at pvv.org
Fri Oct 3 07:16:21 EDT 2003


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





More information about the Python-list mailing list