0

I recently installed gcc 4.9.2 and found a problem when linking with libs.

The output for search path:

install: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/
programs: =/usr/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/libexec/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/../lib64/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64/:/lib/x86_64-unknown-linux-gnu/4.9.2/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../:/lib/:/usr/lib/

Really, the problematic thing is this:

/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/

I need to change the order of these two libs(so that lib64 has higher search priority), because both dirs have the libstdc++.so.6, and I need to use the one in lib64 folder.

How do I do it?

Please don't:

1, suggest that I change LD_LIBRARY_PATH to explicitly include libstdc++.so.6 as I'm sure there are other things in x86_64-linux-gnu folder that are older versions of that in the lib64 folder - I upgraded g++ from an older version.

2, suggest that I explicitly include that lib64/libstdc++.so.6 in the g++ -L option.

Thanks a lot.

/************************EDIT FOR MORE INFO************************/

Upon the request below, here're some more details about configuration and installation(I downloaded 4.9.2 source from gcc.gnu.org, extracted it and started in the 4.9.2 top level folder):

mkdir ../gcc-build                                   &&
cd    ../gcc-build                                   &&

../gcc-4.9.2/configure                               \
    --prefix=/usr                                    \
    --libdir=/usr/lib                                \
    --enable-shared                                  \
    --enable-threads=posix                           \
    --enable-__cxa_atexit                            \
    --disable-multilib                               \
    --with-system-zlib                               \
    --enable-languages=c,c++ &&
make
h9uest
  • 10,958
  • 3
  • 18
  • 24
  • 1
    How did you install GCC (did you install some package?)? On which Linux distribution? Did you compile it yourself? How did you `.../configure` it? Please edit your question to give more details! – Basile Starynkevitch Feb 22 '15 at 21:58
  • @BasileStarynkevitch Hi Basile. I've updated my question with more details. The Linux distribution is Kali. – h9uest Feb 22 '15 at 23:33
  • How was your system `gcc` configured? Try e.g. `gcc-4.8 -v` ? – Basile Starynkevitch Feb 23 '15 at 02:58
  • On what exact system (e.g. what Linux distribution and version) are you doing that? It might happen that you could have broken your system to the point of needing to re-install it! – Basile Starynkevitch Feb 23 '15 at 03:07
  • @BasileStarynkevitch Kali linux, the latest 1.0.7(installed as an earlier version, and I upgraded it to the latest before installing gcc 4.9.2). There's indeed something weird with the gcc I installed. As a temporary workaround, I set the lib path in LD_LIBRARY_PATH, it worked all fine - until I debugged it with gdb. I tried compiling with -g and in another experiment -ggdb. In both cases, there were no symbols found for any variables in the current stack. I then updated gdb to the latest 7.9 and it did not get better. I'm sure something is wrong with my gcc installation. But how come? – h9uest Feb 23 '15 at 14:04
  • Try at least to reinstall the system GCC. – Basile Starynkevitch Feb 23 '15 at 14:05
  • Yeah I might have to go with the hard approach. I'll try installing it to an isolated directory and see what happens. Will post back. – h9uest Feb 23 '15 at 14:07
  • A side note, the Kali Linux really should include the latest gcc in their main source list. I can't imagine the c/c++ compiler collection is not the latest on a distribution targeted at security folks. – h9uest Feb 23 '15 at 14:10
  • I don't think that a security oriented Linux distribution should pack the latest GCC version. It should pack the most secure GCC.... – Basile Starynkevitch Feb 24 '15 at 09:39

1 Answers1

1

You could have a new (or modify the existing) GCC specs file, documentation is here.

AFAIK, the specs file is in your "install" dir, so for you would be in
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/specs (which you could create if it does not exist).

AFAIK there is some built-in default, but you could configure your system to have an explicit one.

Read also about the debugging options of GCC. You may want to use -dumpspecs to get the built-in default spec.

Details may be highly specific to your system, especially if you compiled GCC from its source code.

I am not familiar enough with specs files to give a reliable solution for your particular issue. You might ask on gcc-help@gcc.gnu.org for details.


NB: I would tend to believe that configuring a gcc with --prefix=/usr (and not a non-system prefix like the default --prefix=/usr/local/ or some --prefix=/opt/ etc...) is a mistake (or at least use also --program-suffix=-4.9). You are likely to mix up your gcc with the system gcc; If you want to replace your system gcc (which is probably dangerous) you should configure your new gcc with the same arguments as your system gcc had. Notice that /usr/bin/gcc -v tells you how was your system gcc configured (to be done before overwriting it).

When compiling a recent GCC 4.9 on some older system I generally would recommend to configure it with --prefix=/usr/local/ and --program-suffix=-4.9 then add /usr/local/bin/ to your $PATH, and use make CC=gcc-4.9 CXX=g++-4.9 for building programs with it.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Hi Basile: I've figured out a way to solve my problem: I made sure my /etc/ld.so.conf has /usr/lib64 before /usr/lib/x86_64-linux-gnu/, and g++(really, ld starts to work fine) then starts to link without a problem(there is now indeed a warning whend I do ldconfig: ldconfig: /usr/lib64/libstdc++.so.6.0.20-gdb.py is not an ELF file - it has the wrong magic bytes at the start.) - but this does not matter as explained here: http://readlist.com/lists/gcc.gnu.org/gcc-help/6/32889.html – h9uest Feb 23 '15 at 23:02
  • In addition, the weird thing happening when I debug with gdb - it goes away too. That means, previously, due to inappropriate directory setting, gdb couldn't function either(I got this conclusion because I did NOT recompile with g++, this means all the symbols must have already been generated previously, just that gdb could not find it/work with it). Thank you for spending time following up with this issue and writing the responses - I appreciate it :) – h9uest Feb 23 '15 at 23:06