Lesson 8

Dates: 6/19/2017
Application compilation and installation on Linux
Linux System Administration

Compilation Procedure

  • Suppose one needs to compile a single source C program, code.c, into an executable binary, code.x
    gcc -o code.x code.c

  • This implies the following implicit compilation steps that also can be done by parts:
    1 Preprocessing
    gcc   -E   code.c   -o   code.i
    #define, #ifdef, #include are processed
    2 Compiling
    gcc   -S   code.i   -o   code.s
    Assembly file, code.s
    3 Asembling
    gcc   -c   code.s   -o   code.o
    Creates object file in the machine language
    4 Linking
    gcc   -c   code.o   -o   code.x
    Code is linked with the other .o object files and libraries into an executable binary

  • If the source code consists of several files and needs libraries to be linked with, the compilation procedure can be done either in one step:
    gcc code.c extra_1.c extra_2.c -o code.x -lextra  
    or multiple steps:
    gcc -c code.c 
    gcc -c extra_1.c
    gcc -c extra_2.c 
    gcc -o code.x code.o extra_1.o extra_2.o -lextra  
    If the header files *.h and the libraries *.a are located in the directories different from the source *.c files, for example ../include and ../lib, their location needs to be specified as follows:
    gcc  -o code.x code.o extra_1.o extra_2.o -I../include -L../lib -lextra 

  • Take me to the Course Website