Current configurations for our classroom/lab machines include multiple versions of the GNU compilers:
module load gcc-latestto add the install directory to your command search path and set other environment variables correctly. If you want this to happen every time you log in, you can add the above command to your .bashrc file. See my notes on the “Modules package” for more about modules.
I strongly encourage students in my classes to always compile C programs with at least the optional flag -Wall, and preferably several additional flags. No sensible person would type them all for every compile, but make can help. Create a file Makefile consisting of the single line
CFLAGS=-std=c99 -Wall -pedantic -O(or whatever options you prefer -- note that the last one is a capital O). Then for example compile foo.c with
make foo(The resulting executable will be called foo rather than the default a.out.)
If you're compiling C++ instead (or in addition), add this line to the Makefile:
CXXFLAGS=-std=c++98 -Wall -pedantic -O(or whatever options you prefer -- if you're using the latest version of g++ you may want to replace -std=c++98 with -std=c++17). Then compile foo++.cpp with
make foo++