cc command in Linux basically stands for C Compiler and is an alternative to gcc or clang command. With the help of this command, users can call the gcc on Linux systems which is used to compile C language codes and create executable files.
The compiler’s essential task is to translate a computer program from one form to another (mostly one language to other). While compiling C program, the compiler actually goes through a number of steps to translate it into machine language which can be executed on targeted platforms.
Table of Contents
Syntax of cc command in Linux
Options available to use with cc command
- -o: Used for compiling the source_file.c, and create an executable output file with a specified name.
- -Wall: Used for compiling source_file.c and check for errors or warnings in the program.
- -w: Compiles source_file.c, but suppresses all the warnings.
- -g: Compiles source_file.c and create a debugging version of the executable output file.
- -c: Compiles source_file.c and created an object file source_file.o that can be later linked to create an executable file.
- -L DIR: Used for searching header files in specified directory while compiling source_file.c.
- -ansi: Alongwith compiling the source_file.c, it also makes sure if the code follows strict ANSI standards.
- -v: Compiles source_file.c and prints a verbose output.
Examples of cc command in Linux
1: Compile a file servo.c, and the output will be written in a.out
2: Compile servo.c and the output will be written to servo.exe
cc servo.c -o servo.exe
3: Compile servo.c and output will be written in servo.exe, while the warnings will be displayed if occurs
cc servo.c -Wall -o servo.exe
4: Compile servo.c to servo.exe, while linking the libX11 library and showing warnings if occur
cc servo.c -Wall -lX11 -o servo.exe
5: Compile servo.c to servo.exe, while linking the libX11 library and follow the ANSI C standards. Also to show all warnings if occur.
cc servo.c -Wall -ansi -lX11 -o servo.exe
Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.