1

I am new to C++ compiler. I wonder how can I change some setting of g++ to call the right ld version that I want.

For exmaple, I tried:

g++ "some shared libraries and files"

then /usr/bin/ld will be called internally. What should I do to make g++ call /home/alex/binutils-2.25/bin/ld instead ?

Thank you so much.

Alex

AlexPham
  • 311
  • 2
  • 4
  • 16

1 Answers1

4

Not the best idea in general, because these two are tightly integrated and there is a reason GCC has its own search paths with the appropriate tools for that particular build of GCC, so it's better to switch toolchain as a whole.

Anyway, the link provided by Jean-François Fabre is right in its -B parameter suggestion and not so right about PATH environment variable, because PATH is only searched when there is no match in GCCs internal paths, and usually there is something there.

You can take a look at the current paths used by GCC to find its components with g++ -print-search-dirs, you're interested in programs. It's also easy to check where exactly your compiler finds ld (or any other component) with g++ -print-prog-name=ld, it also allows to check how -B affects the result, like:

$ g++ -print-prog-name=ld
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld
$ g++ -B/home/rik/bin -print-prog-name=ld
/home/rik/bin/ld

Compare that to

$ PATH=/home/rik/bin:$PATH g++ -print-prog-name=ld
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld

[edit]

And BTW, even this won't help you if your GCC was specifically configured using --with-ld option (not the usual way, but), that overrides all other paths.

Roman Khimov
  • 4,807
  • 1
  • 27
  • 35