g++ 2.95.2 -fhonor-std fails to link std::terminate()
llewelly@dbritsch.dsl.xmission.com
llewelly@dbritsch.dsl.xmission.com
Sun Apr 23 21:28:00 GMT 2000
On Thu, 20 Apr 2000, Martin Sebor wrote:
> Hi,
>
> the linker is failing to find std::terminate() when linking exception
> code compiled with -fhonor-std. We're currently providing our own
> definition of the missing function(s) but, since this is surely a known
> problem, I'm wondering whether perhaps there is an option that would let
> the linker use the globals.
>
> Thanks
> Martin
>
> $ cat test.cpp
>
> int main ()
> try { }
> catch (...) { }
>
> $ g++ -fhonor-std test.cpp
> /tmp/ccyIx02a.o: In function `main':
> /tmp/ccyIx02a.o(.text+0x61): undefined reference to
> `std::terminate(void)'
> collect2: ld returned 1 exit status
>
This is because libgcc and libstdc++ are (in 2.95.2) compiled with
-fno-honor-std (the default) and so std::terminate() has the link-time
name 'terminate'.
The workaround is to recompile libstdc++ and libgcc with -fhonor-std.
Unfortunately, I do not remember the official way to do this.
I did it by changing the value of flag_honor_std (to 1) in gcc/cp/decl2.c
and rebuilding gcc . This turns on -fhonor-std on by default.
Note that you if you build a c++ project with such a patched compiler,
will *not* link against a libstdc++ that was built with -fno-honor-std .
I have attached a diff, which works for me, but I am not using the patched
gcc 2.95.2 in a production environment.
*** old/gcc-2.95.2/gcc/cp/decl2.c Thu Aug 19
17:29:45 1999
--- new/gcc-2.95.2/gcc/cp/decl2.c Fri Apr 14
21:42:12 2000
***************
*** 449,455 ****
/* Nonzero to not ignore namespace std. */
! int flag_honor_std;
/* Maximum template instantiation depth. Must be at least 17 for ANSI
compliance. */
--- 449,455 ----
/* Nonzero to not ignore namespace std. */
! int flag_honor_std = 1;
/* Maximum template instantiation depth. Must be at least 17 for ANSI
compliance. */
More information about the Gcc-bugs
mailing list