[Bug middle-end/54630] [4.8 Regression] GCC 4.8 --enable-languages=c build fails: Undefined symbols: ___cxa_guard_acquire and ___cxa_guard_release
baker at usgs dot gov
gcc-bugzilla@gcc.gnu.org
Fri Sep 21 18:58:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54630
--- Comment #4 from Larry Baker <baker at usgs dot gov> 2012-09-21 18:56:20 UTC ---
Richard,
On both Mac OS X and Linux, the link step uses gcc.
On Mac OS X, the link succeed; on Linux, the link fails.
The LINKER is selected by the following logic in the gcc/Makefile:
# The name of the compiler to use.
COMPILER = $(CXX)
COMPILER_FLAGS = $(CXXFLAGS)
# If HOST_LIBS is set, then the user is controlling the libraries to
# link against. In that case, link with $(CC) so that the -lstdc++
# library is not introduced. If HOST_LIBS is not set, link with
# $(CXX) to pick up -lstdc++.
ifeq ($(HOST_LIBS),)
LINKER = $(CXX)
LINKER_FLAGS = $(CXXFLAGS)
else
LINKER = $(CC)
LINKER_FLAGS = $(CFLAGS)
endif
The reason LINKER is set to gcc on both systems is I use the configure
--with-host-libstdcxx option:
Mac OS X: --with-host-libstdcxx='-lstdc++ -lm'
Linux: --with-host-libstdcxx='-static-libgcc -static-libstdc++ -lm'
(I don't know why the -lm is there; I copied that from Sourcery's ColdFire
uClinux SDK build script.)
which defines HOST_LIBS in gcc/Makefile:
# Libraries to use on the host.
Mac OS X: HOST_LIBS = -lstdc++ -lm
Linux: HOST_LIBS = -static-libgcc -static-libstdc++ -lm
The original --with-host-libstdcxx from Sourcery (Mentor Graphics) ColdFire
uClinux SDK build scripts was:
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
I guess Sourcery used '-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' so
that the cross compilers would not have system library dependencies, and could
be delivered in a tarball that would work on many Linux systems without
introducing a shared-llibrary dependency.
I altered that to use the more recent gcc option -static-libstdc++ in place of
-Wl,-Bstatic,-lstdc++,-Bdynamic.
I'm thinking a couple things are happening:
• On Mac OS X, the link works because I do not use static libraries (Mac OS X
does not support them), and -lstdc++ brings in the O/S version of guard.cc.
• On CentOS Linux 6.3, gcc is too old to recognize -static-libstdc++. (I'm
assuming a more recent gcc driver recognizes it; it may be that it is only
recognized by the g++ driver.) I'll try to make a more recent HOST gcc that
supports -static-libstdc++. (Anyone know which release added it?)
However, I do not understand the logic of selecting gcc in the first place.
--with-host-libstdcxx is described at
http://gcc.gnu.org/install/configure.html:
--with-host-libstdcxx=linker-args
If you are linking with a static copy of PPL, you can use this option to
specify how the linker should find the standard C++ library used internally by
PPL. Typical values of linker-args might be `-lstdc++' or
`-Wl,-Bstatic,-lstdc++,-Bdynamic -lm'. If you are linking with a shared copy of
PPL, you probably do not need this option; shared library dependencies will
cause the linker to search for the standard C++ library automatically.
This implies two things to me:
1) This is the only way to pass linker args (that I could find)
2) This is for c++ (...-libstdcxx means c++, right?)
The "linker-args" get turned into HOST_LIBS in gcc/Makefile, used to define
LIBS and BACKENDLIBS:
# How to link with both our special library facilities
# and the system's installed libraries.
LIBS = libcommon.a $(CPPLIB) $(LIBINTL) $(LIBICONV) $(LIBIBERTY) \
$(LIBDECNUMBER) $(HOST_LIBS)
BACKENDLIBS = $(CLOOGLIBS) $(GMPLIBS) $(PLUGINLIBS) $(HOST_LIBS) \
$(ZLIB)
which, to me, means something different than "linker-args".
It seems to me that a main program compiled by g++ should be linked by g++.
Linker args are a separate matter.
In any case, the web page should probably be updated to warn that
--with-host-libstdcxx causes ALL linking (at least for the compilers) to use
gcc instead of g++. This matters now because GCC's implementation language
changes from C to C++ with release 4.8.
More information about the Gcc-bugs
mailing list