This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC 4.2.0: optimisation appears to break C++ compile/link
- From: Lionel B <lionelbuk at yahoo dot co dot uk>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 19 Jun 2007 13:56:50 +0000 (UTC)
- Subject: GCC 4.2.0: optimisation appears to break C++ compile/link
Greetings,
I installed GCC 4.2.0 on linux x86_64, configured as follows:
# cd <objdir>
# <srcdir>/configure --prefix=<instdir> --enable-languages=c,c++,fortran
--enable-version-specific-runtime-libs --with-build-time-
tools=<binutilsdir> --with-as=<binutilsdir>/as --with-ld=<binutilsdir>/ld
where:
<objdir> is the build directory
<srcdir> contains GCC 4.2.0 sources,
<instdir> contains the new GCC installation
<binutilsdir> contains binutils binaries (ver 2.17, compiled with system
gcc 3.4.6)
None of <objdir>, <srcdir>, instdir>, <binutilsdir> is a subdir of
another.
make and make install proceeded without any apparent problems.
I have tested the installation on a C++ "Hello world"
// hello.cpp:
#include <iostream>
int main()
{
std::cout << "hello world\n";
return 0;
}
Compiling as:
# <instdir>/g++ hello.cpp -o hello
<binutilsdir>/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
This is fixable by specifying -static-libgcc (or by -L<instdir>/lib/gcc/
x86_64-unknown-linux-gnu/lib64) and the program runs correctly.
(BTW - why should this be necessary? Does it indicate a problem?)
However, if I try to optimise, eg.
# <instdir>/g++ hello.cpp -O -static-libgcc -o hello
the program compiles and links ok, but running it gives:
# ./hello
./hello: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found
(required by ./hello)
The same happens at higher optimisation levels. The problem does not
appear to affect C (as opposed to C++) code; eg.
/* hello.c */
#include <stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
# <instdir>/gcc hello.c -O -static-libgcc -o hello
yields a correctly functioning program.
I have installed GCC 4.1.2 in exactly the same way and don't see this
problem.
Anyone seen this before?
Regards,
--
Lionel B