First, I'd like to let you know that it is my first post on StackOverflow, so I hope that I won't make a fool of myself by asking a very stupid question. I've been googling about this problem for a few days now, and I couldn't find any answer so far.
Here is the situation:
I'm working on a C++ project managed with autotools. The target platform is RHEL5 64bit with two versions of gcc installed:
- gcc 4.1.2 installed in /usr
- gcc 4.3.5 installed in /local/opt/gcc-4.3.5
When I'm building my project with the default gcc version (4.1.2), everything goes fine, but when I'm switching to gcc 4.3.5, I'm getting this error at link time:
/local/opt/gcc-4.3.5/lib/../lib/libstdc++.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
It seems that libtool hardcoded the path to the 32-bit version of libstdc++.so in the command line, while it should have been the 64-bit version. More precisely, the libtool call that fails is:
/bin/sh ./libtool --tag=CXX --mode=link g++ -m64 -o libfoo.la -rpath /local/opt/foo/lib src/foo/libfoo_la-bar1.lo src/foo/libfoo_la-bar2.lo
It is translated by libtool as:
g++ -shared -nostdlib
/usr/lib/../lib64/crti.o
/local/opt/gcc-4.3.5/lib/gcc/x86_64-unknown-linux-gnu/4.3.5/crtbeginS.o
src/foo/.libs/libfoo_la-bar1.o
src/foo/.libs/libfoo_la-bar2.o
-Wl,--rpath
-Wl,/local/opt/gcc-4.3.5/lib/../lib
-Wl,--rpath
-Wl,/local/opt/gcc-4.3.5/lib/../lib
-L/local/opt/gcc-4.3.5/lib/gcc/x86_64-unknown-linux-gnu/4.3.5
-L/local/opt/gcc-4.3.5/lib/gcc/x86_64-unknown-linux-gnu/4.3.5/../../../../lib64
-L/lib/../lib64
-L/usr/lib/../lib64
-L/local/opt/gcc-4.3.5/lib/gcc/x86_64-unknown-linux-gnu/4.3.5/../../..
/local/opt/gcc-4.3.5/lib/../lib/libstdc++.so
-lm -lc -lgcc_s
/local/opt/gcc-4.3.5/lib/gcc/x86_64-unknown-linux-gnu/4.3.5/crtendS.o
/usr/lib/../lib64/crtn.o
-m64 -Wl,-soname -Wl,libfoo.so.0 -o .libs/libfoo.so.0.0.0
I should precise that the method I use to switch from default gcc to gcc 4.3.5 is the following:
$ export PATH=/local/opt/gcc-4.3.5/bin:$PATH
$ export LD_LIBRARY_PATH=/local/opt/gcc-4.3.5/lib:/local/opt/gcc-4.3.5/lib64:$LD_LIBRARY_PATH
$ export GCC_HOME=/local/opt/gcc-4.3.5
I'm quite new to all these tools, so I suspect I'm doing something wrong. I would be very grateful if anyone could give me a clue as to how to fix this.
Cheers
./configure CC="/local/opt/gcc-4.3.5/bin/gcc-4.3.5 -m64"
– Azeria-lstdc++
instead. – PasqualeCXX= ... g++-4.3.5
, but I doubt it would help. The only other thing that comes to mind is the-B<prefix>
option. – AzeriaCC=...
byCXX=...
didn't solve the problem. The-B<prefix>
didn't help either, which was to be expected since the full path to libstdc++.so is explicitly mentioned in the command line. BTW, I'm unfamiliar with the-B
option, so I put it in LDFLAGS -- I don't know if that's what you meant. Thanks anyway for your time. – Pasqualeexport LD_LIBRARY_PATH=/local/opt/gcc-4.3.5/lib:/local/opt/gcc-4.3.5/lib64:$LD_LIBRARY_PATH
intoexport LD_LIBRARY_PATH=/local/opt/gcc-4.3.5/lib64:/local/opt/gcc-4.3.5/lib:$LD_LIBRARY_PATH
. Also I don't understand why do you provide path to both lib and lib64, I think lib64 should be enough. – Bias