Boost logo

Boost :

From: Christoph Ludwig (cludwig_at_[hidden])
Date: 2004-05-10 05:14:59

While testing gcc 3.4 (on a x86 PC running Linux), I encountered
linker errors due to missing pthread symbols, even though my program
is single threaded. I found that some translation units using
boost::shared_ptr included boost/detail/lwm_nop.hpp whereas other
translation units included boost/detail/lwm_pthreads.hpp. I didn't
observe any errors with gcc 3.3.x.

The problem turns out to be that gcc 3.4 defines the preprocessor
variable _REENTRANT if certain standard library headers are included
even if the compiler is *not* called with the '-pthread' command line
option. The following test exhibits this behavior and shows that it
causes BOOST_HAS_THREADS to be erroneously defined in
boost/config/suffix.hpp if, e.g., the standard header string is

 cludwig_at_lap200:~/C++/gcc3.4/tmp> g++ -v
  Lese Spezifikationen von
  Konfiguriert mit: ../gcc-3.4.0/configure --prefix=/opt/gcc/gcc-3.4.0
  --enable-threads=posix --enable-version-specific-runtime-libs
  --enable-languages=c,c++ --enable-__cxa_atexit --enable-c-mbchar
  --enable-concept-checks --enable-libstdcxx-debug --enable-c99
  Thread-Modell: posix
  gcc-Version 3.4.0

  cludwig_at_lap200:~/C++/gcc3.4/tmp> cat
  #if defined(WITH_STRING_HEADER)
  # include <string>

  #include <boost/config.hpp>

  #if defined(__MT__)
  # warning "__MT__ defined"

  #if defined(_MT)
  # warning "_MT defined"

  #if defined(_REENTRANT)
  # warning "_REENTRANT defined"

  #if defined(_PTHREADS)
  # warning "_PTHREADS defined"

  #if defined(BOOST_HAS_THREADS)
  # warning "BOOST_HAS_THREADS defined"

  cludwig_at_lap200:~/C++/gcc3.4/tmp> g++ -c -I ../boost_1_31_0/

  cludwig_at_lap200:~/C++/gcc3.4/tmp> g++ -c -I ../boost_1_31_0/ -DWITH_STRING_HEADER Warnung: #warning "_REENTRANT defined" Warnung: #warning "BOOST_HAS_THREADS defined"

I have no idea what the gcc developers recommend in order to detect
multi-threading support or if this should be reported to the gcc
developers as a bug. But it will certainly break many programs using

A user can work around this problem by either including
boost/config.hpp before any other headers (even Boost headers since
boost/lexical_cast.hpp, for example, includes string before
boost/config.hpp). Or the user builds everything with MT-support, even
if the program itself is single threaded. Neither workaround is



PS: FWIW, I could trace back the problem to a change in
    include/c++/i686-pc-linux-gnu/bits/gthr-default.h. This change was
    discussed in


Boost list run by bdawes at, gregod at, cpdaniel at, john at