简体   繁体   中英

multiple gcc versions in makefile

In my Makefile I have

CC=g++

When I do mgrep gcc, I have several versions listed like: gnu/gcc/4.2.1 gnu/gcc/4.7.3 etc

I can do a module load to change my gcc version.

Now suppose I want to use multiple versions simultaneously in different makefiles, how do I do it?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM