Hi all,
I'm experiencing some trouble using libtool inside the GNU autotools
collection. My compiled objects do not find their shared libraries that are
installed in non-standard library paths.
I wrote a C++ library, called rtcom for argument's sake, and used SWIG to make
it available as a Python module, rtcom.py. Now SWIG generates some glue C++
code which should be compiled as _rtcom.so. This shared object must lie
somewhere in Python's search path. _rtcom.so obviously needs to link at
runtime to rtcom.so, the original C++ library.
For various reasons, however, I do not want to install rtcom.so in the
standard library directories. This generally is not a problem, as linking an
object using ld --rpath <LibraryPath>, it is possible to tell the dynamic
linker where to find a shared library.
As I understand it, this is a typical libtool task. I used the following
Makefile.am to generate the tools:
############## Makefile.am #########################
BUILT_SOURCES = rtcom_wrap.cpp rtcom_wrap.h
SWIG_SOURCES = rtcom.i
pkgpython_PYTHON = rtcom.py
pkgpyexec_LTLIBRARIES = _rtcom.la
_rtcom_la_SOURCES = $(BUILT_SOURCES) $(SWIG_SOURCES)
_rtcom_la_CPPFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)
_rtcom_la_LDFLAGS = -module
_rtcom_la_LIBADD = ../librtcom.la
-include $(DEPDIR)/rtcom_wrap.d
rtcom_wrap.cpp: $(SWIG_SOURCES)
$(SWIG) $(SWIG_PYTHON_OPT) -I$(top_srcdir) \
-MMD -MF $(DEPDIR)/rtcom_wrap.d -o $@ $<
rtcom_wrap.h: $(SWIG_SOURCES)
$(SWIG) $(SWIG_PYTHON_OPT) -I$(top_srcdir) \
-MMD -MF $(DEPDIR)/rtcom_wrap.d -oh $@ $<
##################################################
make install calls:
../libtool --mode=install /usr/bin/install -c '_rtcom.la' \
'/opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.la'
which in turn calls:
/bin/sh ../libtool --tag=CXX --mode=relink g++ -g -O2 \
-o _rtcom.la \
-rpath /opt/etherlab/lib/python2.5/site-packages/rtcom \
-module _rtcom_la-rtcom_wrap.lo ../librtcom.la -lexpat
The relink calls g++, however _without_ the necessary
"-Wl,--rpath -Wl,/opt/etherlab/lib" options to g++
The complete install log is attached.
It is then no surprise that loading the module under Python fails:
---------------------------------------------------
>>> import sys
>>> sys.path.append('/opt/etherlab/lib/python2.5/site-packages/rtcom')
>>> import rtcom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/etherlab/lib/python2.5/site-packages/rtcom/rtcom.py", line 5, in
<module>
import _rtcom
ImportError: librtcom.so.2: cannot open shared object file: No such file or
directory
---------------------------------------------------
As a workaround, I replace _rtcom_la_LDFLAGS in Makefile.am with:
_rtcom_la_LDFLAGS = -module -Wl,--rpath -Wl,$(libdir)
Then it works.
As I understand it, this should be libtool's task. All the necessary
information about where rtcom.so is installed is contained in the rtcom.la
file. What am I missing out on here?
My autotools configuration is:
autoconf-2.60-21
automake-1.9.6-35
libtool-1.5.22-34
I am also using ac_pkg_swig.m4 ac_python_devel.m4 swig_enable_cxx.m4
swig_python.m4 downloaded from http://autoconf-archive.cryp.to/
Many thanks in advance for any help.
- Richard
make install-am
make[1]: Entering directory `/home/rich/msr-gate/rtcom/pyext'
make[2]: Entering directory `/home/rich/msr-gate/rtcom/pyext'
test -z "/opt/etherlab/lib/python2.5/site-packages/rtcom" || mkdir -p -- "/opt/etherlab/lib/python2.5/site-packages/rtcom"
/bin/sh ../libtool --mode=install /usr/bin/install -c '_rtcom.la' '/opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.la'
libtool: install: warning: relinking `_rtcom.la'
(cd /home/rich/msr-gate/rtcom/pyext; /bin/sh ../libtool --tag=CXX --mode=relink g++ -g -O2 -o _rtcom.la -rpath /opt/etherlab/lib/python2.5/site-packages/rtcom -module _rtcom_la-rtcom_wrap.lo ../librtcom.la -lexpat )
g++ -shared -nostdlib /usr/lib/gcc/i586-suse-linux/4.1.2/../../../crti.o /usr/lib/gcc/i586-suse-linux/4.1.2/crtbeginS.o .libs/_rtcom_la-rtcom_wrap.o -L/opt/etherlab/lib -lrtcom -lexpat -L/usr/lib/gcc/i586-suse-linux/4.1.2 -L/usr/lib/gcc/i586-suse-linux/4.1.2/../../../../i586-suse-linux/lib -L/usr/lib/gcc/i586-suse-linux/4.1.2/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/i586-suse-linux/4.1.2/crtendS.o /usr/lib/gcc/i586-suse-linux/4.1.2/../../../crtn.o -Wl,-soname -Wl,_rtcom.so.0 -o .libs/_rtcom.so.0.0.0
/usr/bin/install -c .libs/_rtcom.so.0.0.0T /opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.so.0.0.0
(cd /opt/etherlab/lib/python2.5/site-packages/rtcom && { ln -s -f _rtcom.so.0.0.0 _rtcom.so.0 || { rm -f _rtcom.so.0 && ln -s _rtcom.so.0.0.0 _rtcom.so.0; }; })
(cd /opt/etherlab/lib/python2.5/site-packages/rtcom && { ln -s -f _rtcom.so.0.0.0 _rtcom.so || { rm -f _rtcom.so && ln -s _rtcom.so.0.0.0 _rtcom.so; }; })
/usr/bin/install -c .libs/_rtcom.lai /opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.la
/usr/bin/install -c .libs/_rtcom.a /opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.a
chmod 644 /opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.a
ranlib /opt/etherlab/lib/python2.5/site-packages/rtcom/_rtcom.a
PATH="$PATH:/sbin" ldconfig -n /opt/etherlab/lib/python2.5/site-packages/rtcom
----------------------------------------------------------------------
Libraries have been installed in:
/opt/etherlab/lib/python2.5/site-packages/rtcom
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/opt/etherlab/lib/python2.5/site-packages/rtcom" || mkdir -p -- "/opt/etherlab/lib/python2.5/site-packages/rtcom"
/usr/bin/install -c -m 644 'rtcom.py' '/opt/etherlab/lib/python2.5/site-packages/rtcom/rtcom.py'
Byte-compiling python modules...
rtcom.py
Byte-compiling python modules (optimized versions) ...
rtcom.py
make[2]: Leaving directory `/home/rich/msr-gate/rtcom/pyext'
make[1]: Leaving directory `/home/rich/msr-gate/rtcom/pyext'
_______________________________________________
http://lists.gnu.org/mailman/listinfo/libtool