rpath in setup.py?

T

Tore Ferner

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
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Tore said:
[...] 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
 
T

Tore Ferner

Gerhard said:
> 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
 
M

Marc Recht

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
 
T

Tore Ferner

Marc said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top