libtool links with 32-bit version of libstdc++.so on a 64-bit target platform when multiple version of gcc are installed
Asked Answered
P

1

13

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

Pasquale answered 3/4, 2013 at 8:32 Comment(7)
This seems strange. I would expect gcc-4.3.5 to have hardcoded paths for the 64 bit libraries. Try: ./configure CC="/local/opt/gcc-4.3.5/bin/gcc-4.3.5 -m64"Azeria
Thank you for your answer Brett. I tried your suggestion but it didn't change the outcome. What bugs me is that, when I compile with the default gcc version, libstdc++.so is not explicitly mentioned in the command line. Libtool produces the option -lstdc++ instead.Pasquale
I should have said: CXX= ... g++-4.3.5, but I doubt it would help. The only other thing that comes to mind is the -B<prefix> option.Azeria
As you feared, replacing CC=... by CXX=... 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.Pasquale
Libtool uses .la/.lo files as part of determining the appropriate libraries to link against. In this case, check the libstdc++.la file along your library path as libtool will find it and use it to find libstdc++.so.Indubitable
Is it really the 64-bit version of libstdc++ you have in /local/opt/gcc-4.3.5/lib? Did you compile and install gcc-4.3.5 yourself (the location of libstdc++ suggests you didn't)? Otherwise you might have a bad mix of 32-bit only and dual ABI libraries.Raising
Try changing export LD_LIBRARY_PATH=/local/opt/gcc-4.3.5/lib:/local/opt/gcc-4.3.5/lib64:$LD_LIBRARY_PATH into export 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
P
7

I've just found the answer to my own question: in addition to setting correctly LD_LIBRARY_PATH, I needed to pass the argument LDFLAGS=-L/local/opt/gcc-4.3.5/lib64 to the configure script. Thank you all for your inputs.

Pasquale answered 17/12, 2013 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.