|
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
included:
cludwig_at_lap200:~/C++/gcc3.4/tmp> g++ -v
Lese Spezifikationen von
/opt/gcc/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
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
--enable-libstdcxx-pch
Thread-Modell: posix
gcc-Version 3.4.0
cludwig_at_lap200:~/C++/gcc3.4/tmp> cat test-BOOST_HAS_THREADS.cc
#if defined(WITH_STRING_HEADER)
# include <string>
#endif
#include <boost/config.hpp>
#if defined(__MT__)
# warning "__MT__ defined"
#endif
#if defined(_MT)
# warning "_MT defined"
#endif
#if defined(_REENTRANT)
# warning "_REENTRANT defined"
#endif
#if defined(_PTHREADS)
# warning "_PTHREADS defined"
#endif
#if defined(BOOST_HAS_THREADS)
# warning "BOOST_HAS_THREADS defined"
#endif
cludwig_at_lap200:~/C++/gcc3.4/tmp> g++ -c -I ../boost_1_31_0/ test-BOOST_HAS_THREADS.cc
cludwig_at_lap200:~/C++/gcc3.4/tmp> g++ -c -I ../boost_1_31_0/ -DWITH_STRING_HEADER test-BOOST_HAS_THREADS.cc
test-BOOST_HAS_THREADS.cc:16:4: Warnung: #warning "_REENTRANT defined"
test-BOOST_HAS_THREADS.cc:24:4: 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
Boost.
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
satisfying.
Regards
Christoph
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
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01607.html.
-- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk