C Language Compilation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

The C language is traditionally a compiled language (as opposed to interpreted). The C Standard defines translation phases, and the product of applying them is a program image (or compiled program). In , the phases are listed in §5.1.1.2.

Remarks

Filename extensionDescription
.cSource file. Usually contains definitions and code.
.hHeader file. Usually contains declarations.
.oObject file. Compiled code in machine language.
.objAlternative extension for object files.
.aLibrary file. Package of object files.
.dllDynamic-Link Library on Windows.
.soShared object (library) on many Unix-like systems.
.dylibDynamic-Link Library on OSX (Unix variant).
.exe, .comWindows executable file. Formed by linking object files and library files. In Unix-like systems, there is no special file name extension for executable file.
POSIX c99 compiler flagsDescription
-o filenameOutput file name eg. (bin/program.exe, program)
-I directorysearch for headers in direrctory.
-D namedefine macro name
-L directorysearch for libraries in directory.
-l namelink library libname.

Compilers on POSIX platforms (Linux, mainframes, Mac) usually accept these options, even if they are not called c99.

GCC (GNU Compiler Collection) FlagsDescription
-WallEnables all warning messages that are commonly accepted to be useful.
-WextraEnables more warning messages, can be too noisy.
-pedanticForce warnings where code violates the chosen standard.
-WconversionEnable warnings on implicit conversion, use with care.
-cCompiles source files without linking.
-vPrints compilation info.
  • gcc accepts the POSIX flags plus a lot of others.
  • Many other compilers on POSIX platforms (clang, vendor specific compilers) also use the flags that are listed above.
  • See also Invoking GCC for many more options.
TCC (Tiny C Compiler) FlagsDescription
-Wimplicit-function-declarationWarn about implicit function declaration.
-WunsupportedWarn about unsupported GCC features that are ignored by TCC.
-Wwrite-stringsMake string constants be of type const char * instead of char *.
-WerrorAbort compilation if warnings are issued.
-WallActivate all warnings, except -Werror, -Wunusupported and -Wwrite strings.


Got any C Language Question?