Compile and run C program

Last update in 11/2019

For compiling C programs you'll have to use either gcc or clang. Both produce almost identical results so it doesn't really matter which one you choose for exploring and hobby usage. This post will use gcc.

You most likely have gcc already installed. Try running this command in terminal.

gcc --version

If you get command doesn't exist or similar error, try to install gcc using guide from its website.

gcc your_program.c

This will compile binary in same folder that you can actually run.


Programs made from multiple files can also be compiled.

gcc file_1.c file_2.c file_3.c

Also, you can change name of compiled program with -o option.

gcc your_program.c -o another_name