[pkg-boost-devel] Bug#593876: libboost-filesystem-dev: Undeclared indirect dependency of boost_filesystem on boost_system causes link failure

Roger Leigh rleigh at debian.org
Sat Aug 21 19:19:17 UTC 2010


Package: libboost-filesystem-dev
Version: 1.42.0.1
Severity: normal

Hi,

Given this trivial example program:

#include <boost/filesystem.hpp>
int
main ()
{
  boost::filesystem::is_directory("/");
  return 0;
}

This program compiles and links fine with GCC 4.4:

% g++-4.4 -o test.o -c test.cc                 
% g++-4.4 -o test test.cc -lboost_filesystem-mt
% ./test

However, it fails to build with the binutils-gold linker unless
it's also linked against libboost_system:

% g++-4.4 -o test.o -c test.cc                 
% g++-4.4 -o test test.cc -lboost_filesystem-mt
/usr/bin/ld.gold.real: /tmp/ccsAmwMn.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x81): error: undefined reference to 'boost::system::get_system_category()'
/usr/bin/ld.gold.real: /tmp/ccsAmwMn.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x8d): error: undefined reference to 'boost::system::get_generic_category()'
/usr/bin/ld.gold.real: /tmp/ccsAmwMn.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x99): error: undefined reference to 'boost::system::get_generic_category()'
/usr/bin/ld.gold.real: /tmp/ccsAmwMn.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0xa5): error: undefined reference to 'boost::system::get_generic_category()'
/usr/bin/ld.gold.real: /tmp/ccsAmwMn.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0xb1): error: undefined reference to 'boost::system::get_system_category()'
/usr/bin/ld.gold.real: /tmp/ccsAmwMn.o: in function boost::system::error_code::error_code():test.cc(.text._ZN5boost6system10error_codeC1Ev+0x17): error: undefined reference to 'boost::system::get_system_category()'
collect2: ld returned 1 exit status
% g++-4.4 -o test test.cc -lboost_filesystem-mt -lboost_system-mt

It also fails with GCC 4.5 with or without binutils-gold installed:

Without binutils-gold:

% g++-4.5 -o test.o -c test.cc                                   
% g++-4.5 -o test test.cc -lboost_filesystem-mt                  
/usr/bin/ld.bfd.real: /tmp/ccRq6TYh.o: undefined reference to symbol 'boost::system::get_system_category()'
/usr/bin/ld.bfd.real: note: 'boost::system::get_system_category()' is defined in DSO /usr/lib64/libboost_system.so.1.42.0 so try adding it to the linker command line
/usr/lib64/libboost_system.so.1.42.0: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
% g++-4.5 -o test test.cc -lboost_filesystem-mt -lboost_system-mt


With binutils-gold:

% g++-4.5 -o test.o -c test.cc                                   
% g++-4.5 -o test test.cc -lboost_filesystem-mt
/usr/bin/ld.gold.real: /tmp/ccgfktx6.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x76): error: undefined reference to 'boost::system::get_system_category()'
/usr/bin/ld.gold.real: /tmp/ccgfktx6.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x82): error: undefined reference to 'boost::system::get_generic_category()'
/usr/bin/ld.gold.real: /tmp/ccgfktx6.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x8e): error: undefined reference to 'boost::system::get_generic_category()'
/usr/bin/ld.gold.real: /tmp/ccgfktx6.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0x9a): error: undefined reference to 'boost::system::get_generic_category()'
/usr/bin/ld.gold.real: /tmp/ccgfktx6.o: in function __static_initialization_and_destruction_0(int, int):test.cc(.text+0xa6): error: undefined reference to 'boost::system::get_system_category()'
/usr/bin/ld.gold.real: /tmp/ccgfktx6.o: in function boost::system::error_code::error_code():test.cc(.text._ZN5boost6system10error_codeC2Ev+0x17): error: undefined reference to 'boost::system::get_system_category()'
collect2: ld returned 1 exit status
% g++-4.5 -o test test.cc -lboost_filesystem-mt -lboost_system-mt


Why is this a problem?

The fact that boost_filesystem depends upon boost_system is an
internal implementation detail that is exposed in the public headers--
I'm not making direct use of it myself.  This requires me as an end
user of the library to have knowledge of the internals in order to
correct link.  Worse, if those internals ever change, my program will
fail to build with linker errors as above, which makes supporting
multiple boost versions difficult.

% ldd /usr/lib/libboost_filesystem.so.1.42.0 | grep boost_system
	libboost_system.so.1.42.0 => /usr/lib/libboost_system.so.1.42.0 (0x0000003852c00000)

The actual libboost_filesystem DSO does declare the dependency as
shown above.  Unfortunately, the use in included headers introduces
a dependency in user code as well.  Newer linkers and compilers have
increased the stringency of dependency checking, so the indirect
dependency via the boost_filesystem DSO is not sufficient for linking.

This is one place where proper support for pkg-config by Boost would
be invaluable: all this specific knowledge would be exposed to the
user in a form which would allow correct integration with project
build systems, including autoconf/automake support for free.

I appreciate that this is difficult to fix directly in Debian, so
please do forward this upstream if you feel it necessary.


Regards,
Roger

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (550, 'unstable'), (400, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages libboost-filesystem-dev depends on:
ii  libboost-filesystem1.42-dev   1.42.0-4   filesystem operations (portable pa

libboost-filesystem-dev recommends no packages.

libboost-filesystem-dev suggests no packages.

-- no debconf information





More information about the pkg-boost-devel mailing list