Any way to tell g++ to use another binary for compiling?

449 Views Asked by At

This question may sound a little absurd. Facts:

  1. I have a program written in C++.
  2. It uses lot of in-house libs.
  3. I don't have read permission to the libs.
  4. So I have to build with a given tool which does have access to the lib headers and archives.
  5. Stuck on gcc 4.3
  6. I have a local build of gcc 4.5
  7. I want g++ to use my local g++ instead of the old version.

Is there any way to get this done?

3

There are 3 best solutions below

1
On

Use the full path of the compiler instead of invoking it without specifying the path.

0
On

Many configure scripts accept the CC environment variable:

export CC=/usr/bin/gcc44 for example. If you have a configure script, try ./configure --help to see if it's supported.

0
On

Assuming you have g++ in your ~/bin folder, could you add

export PATH=~/bin:$PATH

to your shell's .profile file (.bash_profile for bash). Then when you log in again and do which g++ it should show your local version of g++.