cc
Compile C source code
TLDR
View documentation for the original command
SYNOPSIS
cc [options] files...
PARAMETERS
-o output_file
Specifies the name of the output file (executable, object, or library).
-c
Compile or assemble the source files, but do not link. Outputs object files (.o).
-S
Compile source files to assembly code (.s), but do not assemble or link.
-E
Run only the preprocessor stage. Output goes to standard output by default.
-I dir
Add directory dir to the list of directories to be searched for header files.
-L dir
Add directory dir to the list of directories to be searched for library files.
-l lib
Link with the library named lib. The compiler searches for liblib.a or liblib.so.
-Wall
Enable all commonly used warning messages.
-g
Produce debugging information (for use with debuggers like GDB).
-Olevel
Optimize the generated code. level can be 0 (no optimization), 1, 2, 3, or s (size optimization).
-std=version
Specify the C standard to which the code should conform (e.g., c99, c11, gnu11).
DESCRIPTION
cc is a command on Linux systems that typically acts as the default C compiler. Historically, cc referred to the original C compiler provided with Unix systems. On modern Linux distributions, cc is almost invariably a symbolic link to gcc (GNU Compiler Collection) or sometimes clang. Its primary purpose is to compile C source code files into executable programs or object files.
It orchestrates the entire compilation process, which includes preprocessing, compilation (to assembly), assembly (to object code), and linking. While it's primarily associated with C, the underlying gcc or clang compiler supports many other languages like C++, Fortran, and others, though cc specifically implies the C compiler frontend. It's a fundamental tool for software development, allowing developers to turn human-readable source code into machine-executable binaries.
CAVEATS
cc on Linux is typically a symbolic link to a specific compiler, most commonly gcc (GNU Compiler Collection) or sometimes clang. Its behavior and supported options are therefore largely determined by the actual compiler it points to. While it's used for C, the underlying compiler can often handle C++ and other languages, but for explicit C++ compilation, g++ or clang++ are usually preferred.
<B>THE COMPILATION PROCESS</B>
When you invoke cc to compile a source file, it typically goes through several stages:
1. Preprocessing: Handles directives like #include and #define, expanding macros and including header files. Output is an expanded source file.
2. Compilation: Translates the preprocessed code into assembly language specific to the target architecture.
3. Assembly: Converts the assembly code into machine code (object code), typically stored in .o files.
4. Linking: Combines the object files with necessary libraries (like the C standard library) to produce a final executable program or a shared library.
<B>DEFAULT OUTPUT</B>
If no output file name is specified using the -o option, cc will, by default, create an executable file named a.out in the current directory. This name also has historical significance in Unix systems.
HISTORY
The command name cc has historical roots, dating back to the earliest versions of Unix where it referred to the original Bell Labs C compiler. As the C language gained popularity and various compilers emerged, cc became a conventional alias or symbolic link to the system's default C compiler. In the Linux ecosystem, the GNU Compiler Collection (GCC), developed by the GNU Project, became the predominant C compiler, leading to cc almost universally pointing to gcc. This convention ensures that scripts and build systems written for a generic Unix environment can reliably invoke the system's C compiler.