Libtool fails to handle library interdependencies

Bug #1002565 reported by Kristian Spangsege
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libtool (Ubuntu)
New
Undecided
Unassigned

Bug Description

Libtool fails to handle library interdependencies.

The interdependency is specified on the command line, and is recorded correctly by libtool, however, since there is no dependency from the point of view of the binary library files, and since libtool no longer adds all dependency libraries on the command line, compiling of the final application fails.

I suppose the problem is that libtool has been changed to set link_all_deplibs=no on my platform, but I'm not sure.

Here is an example that illustrates the problem:

### create test files:
cat >alpha.hpp <<EOI
void alpha();
EOI
cat >alpha.cpp <<EOI
#include "alpha.hpp"
void alpha() {}
EOI
cat >beta.hpp <<EOI
#include "alpha.hpp"
void beta1();
inline void beta2() { alpha(); }
EOI
cat >beta.cpp <<EOI
#include "beta.hpp"
void beta1() {}
EOI
cat >app.cpp <<EOI
#include "beta.hpp"
int main()
{
  beta2();
  return 0;
}
EOI

### build 'libalpha':
libtool --tag=CXX --mode=compile g++ -c alpha.cpp
libtool --tag=CXX --mode=link g++ alpha.lo -o libalpha.la -rpath /tmp

### build 'libbeta':
libtool --tag=CXX --mode=compile g++ -c beta.cpp
libtool --tag=CXX --mode=link g++ beta.lo libalpha.la -o libbeta.la -rpath /tmp # Depends on 'libalpha'

### build app:
libtool --tag=CXX --mode=link g++ app.cpp libbeta.la -o app

### error:
# In function `beta2()':
# app.cpp: undefined reference to `alpha()'

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: libtool 2.4.2-1ubuntu1
ProcVersionSignature: Ubuntu 3.2.0-24.38-generic 3.2.16
Uname: Linux 3.2.0-24-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 2.0.1-0ubuntu7
Architecture: amd64
Date: Tue May 22 00:37:22 2012
InstallationMedia: Ubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
ProcEnviron:
 LANGUAGE=en_US:en
 TERM=xterm
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: libtool
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Kristian Spangsege (kristian-spangsege) wrote :
Revision history for this message
Kristian Spangsege (kristian-spangsege) wrote :

Of couse, if you forget about C++, then this change is probably ok, since all dependencies would be reflected in the binary library files. This is certainly not the case for C++.

I belive that the Libtool manual says unambiguously that this is supposed to work:

"In any event, libtool provides a simple mechanism for you to declare inter-library dependencies: for every library libname that your own library depends on, simply add a corresponding -lname option to the link line when you create your library."

http://www.gnu.org/software/libtool/manual/libtool.html#Inter_002dlibrary-dependencies

Revision history for this message
Kristian Spangsege (kristian-spangsege) wrote :

Note also that this actually worked in Ubuntu 10.04.

Also see this diff excerpt on libtool.m4 between Ubuntu 10.04 and 12.04:

@@ -4249,10 +4655,39 @@
   openbsd*)
     with_gnu_ld=no
     ;;
+ linux* | k*bsd*-gnu | gnu*)
+ _LT_TAGVAR(link_all_deplibs, $1)=no
+ ;;
   esac

Revision history for this message
Frederik Heber (foo) wrote :

I am not sure whether this is truely Ubuntu's fault.

We are still running 10.04 and I have the same variable set to no for linux systems in libtool.m4 (ltmain.sh says 2.2.6b).

I observe the following:
- if the switc (in the preceding comment) h is set to yes, then linking will proceed correctly. I.e. shared libaries given in the Makefile.am will correctly pull in their _shared_ library dependencies. However, execution of the resulting binary fails as shared libraries are not found. Hence, the rpath setting seems to fail then.
- if the above switch is set to no, then linking will fail as "pulled in" shared library dependencies are not given to gcc on linking causing e.g. undefined reference in vtable errors. If the shared libraries, to pulled in because of dependencies, are explicitly listed in Makefile.am -- besides the shared libraries that have these as dependencies -- then linking and execution commence without error.

There is also a discussion on this topic here: http://comments.gmane.org/gmane.comp.gnu.libtool.general/11643

Revision history for this message
Roman (roman-fietze) wrote :

I have the same problem. On old version of Ubuntu our own and other projects from the web properly compile, link *and* run. The same is true using all other systems we have tested, openSUSE up to 13.1, different Red Hats, Fedoras, Angstroem, Debian (RaspberryPi).

But with Ubuntu 14.04.2 LTS it doesn't work any more.

When I install the original libtool 2.4.2 from the GNU sources on Ubuntu 14.04.2 LTS everything is fine and back to normal. Just setting link_all_deplibs to yes didn't help too much. Linking wasn't a problem, but we had unresolved externals when trying to run binaries, and ldd didn't show the dependencies as well, allthough libtool linked the appropriate libs, probably missing some rpath statements (?).

Changing all autotool files of all our projects, or as a maintainer in the sources from the web is quite some work. And the manual maintenance of the nested dependencies in other libs or executables is not very efficient and redundant work.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.