How to Use Multiple Versions of Gcc

How to use multiple versions of GCC

Refer "How to install multiple versions of GCC" here in the GNU GCC FAQ.

There's also a white paper here.

Switch between different GCC versions

Is the above the best way to achieve this? If so,
what paths should I set while implementing such a function?

As others pointed out, PATH and LD_LIBRARY_PATH are mandatory. You may also update MANPATH for completeness.

Rather than reinventing the wheel in .bashrc I suggest to employ a little known but extremely handy and modular Environment Modules that were designed for this specific purpose. You could use them like (once you set up config for gcc/3.1.1):

$ module load gcc/3.1.1
$ which gcc
/usr/local/gcc/3.1.1/linux/bin/gcc
$ module unload gcc
$ which gcc
gcc not found

How to use 2 different versions of GCC on Linux Ubuntu and force MAKE to use one of them

Make uses some standard variables in order to determine which tools to use, the C-compiler variable is called "CC". You can set the CC variable, either directly in your Makefile

CC=/opt/gcc-4.0.1/bin/gcc

which is fine if you're working alone on it, or everyone has the same setup. Or you can pass it on the command line like so:

make CC=/opt/gcc-4.0.1/bin/gcc

the third option is set /opt/gcc-4.0.1/bin before everything else in your path (which is why it doesn't work for you, the current directory isn't in the path, so the symlink you put there will not be considered when searching)

export PATH=/opt/gcc-4.0.1/bin:$PATH

For completeness, in your symlink solution, you'd have to invoke ./gcc to get the right gcc instance, but IMHO this is probably not the best solution.

HTH

Is it possible to install 2 different versions of GCC at the same time?

Have you searched the Ubuntu package archive for gcc ?

If gcc 3.3 is ok, you could download the gcc-3.3 and related .deb packages for dapper and I suspect it will install and happily co-exist with the gcc 4.4 you get with karmic. (You'll have to be sure to invoke it as gcc-3.3.)

Otherwise you would have to:

  • download the relevant gcc source bundle
  • build it yourself with an installdir some place out of the way like /opt/gcc-3.3
  • make sure to set your PATH correctly when you need it.

multiple gcc versions in makefile

The module system is basically just setting up a path to the requested module. If you want a particular compiler in a particular makefile, then you can do three things:

  1. Expect the user of the makefile to load the correct version before calling Make. Possibly combined with some condition based on gcc -v|grep ${GCC_VERSION} to check that it's the right version.
  2. Perform module load gnu/gcc/${GCC_VERSION} inside your makefile.
  3. Use CC=/somewhere/path-to-gcc-version/bin/g++ instead of CC=g++.

Personally, I prefer 1 or 3. You can find out what the path is by doing module load ... and then which g++.

[By the way, I would use CXX=g++ and CC=gcc - assuming you are not compiling files called *.c as C++-code]

GCC on Mac OSX--multiple versions of gcc

By default, your gcc installations should be in /usr/bin/. So, for example, to use gcc 4.2, you'd use /usr/bin/gcc-4.2 to compile your files. You can do ls /usr/bin/gcc* to see which ones you have installed.

EDIT:
If gcc isn't installed in the default path (i.e., /usr/bin/), then you can execute locate gcc in the terminal to find where it is located.

install multiple versions of g++(or gcc)

In bash you could do two scripts like this:
first one:

export PATH=/path/to/your/3.4.3/bin:$PATH
eclipse&

and

export PATH=/path/to/your/4.6.1/bin:$PATH
eclipse&

By running one of those, eclipse should use first gcc it finds in your path. Also your default gcc should still be primary, if you don't run any scripts.

BTW:
You can probably strike a deal with your professor on what c++ standard he wants you to use (and what libraries), not what outdated version of compiler you should use to compile your code.

compiling source code on 2 different versions of gcc

That's a duplicate of: Why "Redefinition of typedef" error with GCC 4.3 but not GCC 4.6?

The answer is that gcc was changed to modify this check.

http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412

Sometimes, warnings for behavior defined in the language, but considered bad practice, are considered too strict because certain useful and/or harmless use cases are included in the warning. Compiler developers then try to fix in the opposite way, that is, reducing the amount of warnings. In this case, the change made the warning appear only when the second definition changed the typedef to a different, but compatible type.

Other current example is -Wshadow in gcc 4.8 just announced. In the release note, it says that -Wshadow won't warn anymore if a function name is shadowed by another.

See:
http://gcc.gnu.org/gcc-4.8/changes.html

Edit: how you can avoid this: either delete one of the definitions, or move it to a separate include file and delete both other definitions.

How to work with multiple GCC - LLVM and clang

The best way to do this varies greatly by your build system.

For make (and possibly other systems) the C compiler is specified in the CC variable, so you can just call

CC=/path/to/new/gcc make

if the project uses configure scripts from autoconf, you can use something similar

./configure CC=/path/to/new/gcc


Related Topics



Leave a reply



Submit