Rost
Rost

Reputation: 9089

How to enforce already installed gcc-ar to use specific binutils version?

I've built GCC 4.9.3 from sources and installed into my home directory with some prefix, e.g. gcc4.9.

Now I want to use a newer version of binutils along with GCC 4.9.3. I've built them and installed separately in my home directory, with prefix binutils2.26.

How I can force gcc-ar from gcc4.9 to use ar from binutils2.26 instead of system one? It always calls /usr/bin/ar and looks like there is no options to specify. Replacing /usr/bin/ar somehow is not an option - I don't have root access on this machine.

Upvotes: 2

Views: 1897

Answers (2)

Rost
Rost

Reputation: 9089

I managed to fix this issue.

Using strace, I found that gcc-ar looks for ar in several directories, including <gcc install dir>/libexec/gcc/x86_64-redhat-linux/4.9.3.

So the obvious solution is to create links in this directory targeting corresponding binutils2.26 executables:

  cd "<gcc install dir>/libexec/gcc/x86_64-redhat-linux/4.9.3"
  for file in ~/binutils2.26/bin/* ; do ln -s "${file}" ; done

After that all, executables in ~/binutils2.26/bin will be replicated as links in the GCC 4.9.3 directory and will be used automatically when building by that GCC version.

Upvotes: 1

Mike Frysinger
Mike Frysinger

Reputation: 3072

Use GCC's -B flag and point it at the directory that contains the ar you want to execute. See the GCC manual for more details on this flag.

gcc-ar -B/path/to/your/dir ...

It seems to work for me:

$ strace -f -eexecve gcc-ar rc foo.a /dev/null |& grep /ar
[pid 14485] execve("/usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/../../../../x86_64-pc-linux-gnu/bin/ar", [...]) = 0
$ strace -f -eexecve gcc-ar rc foo.a /dev/null -B/usr/bin |& grep /ar
[pid 14493] execve("/usr/bin/ar", [...]) = 0
$ strace -f -eexecve gcc-ar rc foo.a /dev/null -B/usr/x86_64-pc-linux-gnu/binutils-bin/2.26/ |& grep /ar
[pid 14500] execve("/usr/x86_64-pc-linux-gnu/binutils-bin/2.26/ar", [...]) = 0

Upvotes: 2

Related Questions