The default compiler is GCC which includes the gcc program for C and g++ for C++.
If necessary, you can load the gcc module to have a different version from the one included with the system. For example:
module load gcc
It is possible that these version might have unforeseen problems in some circumstances so we recommend that you stick to the default compiler.
|Optimiser the program.
|Debug the program
|Get more warning when compiling.
|Name of the program we want to create
|To create only the object files (.o)
|Add non standard include direcrory
|Add non standard library directory
|Link with a library
If your program is contained in a single file, you can use this command to build an optimized program.
gcc -O -Wall -o hello hello.c
If you need to debug the program, replace
If your program has more than one file, usually objects files are created first and then they are linked together. It's what is done in most Makefile.
gcc -O -Wall -c hello1.c
gcc -O -Wall -c hello2.c
gcc -O -o hello hello1.o hello2.o
As you can see, we're using the
-c option to compile a
.c to an object file
If you have a C++ program, replace gcc by g++
g++ -O -Wall -c hello1.c
g++ -O -Wall -c hello2.c
g++ -O -o hello hello1.o hello2.o
Compile a program with the cplex library.
gcc -O -Wall -DNDEBUG -DIL_STD -c lpex1.c
gcc -O -o lpex1 lpex1.o -lcplex -lm -lpthread
Compile a C++ program with cplex and concert.
g++ -O -Wall -DNDEBUG -DIL_STD -c cutstock.cpp
g++ -O -o cutstock cutstock.o -lilocplex -lconcert -lcplex -lm -lpthread
Compile a C++ program using gurobi
module load gurobi
g++ -o sudoku sudoku_c++.cpp -lgurobi_g++5.2 -lgurobi100