Saturday 23 December 2017

Compiling And Linking in C Programming Language - Geeks4Coding


 Compiling And Linking    



 C systems generally consist of several parts: a program development environment, the language and the C Standard Library. C programs typically go through six phases to be executed. These are: edit, preprocess, compile, link, load and execute.
 


Creating a Program


Edit a file. This is accomplished with an editor program. Software packages for the C/C++ integrated program development environments such as Eclipse, Codeblock and Microsoft Visual Studio have editors that are integrated into the programming environment. 

You type a C program with the editor, make corrections if necessary, and then store the program on a secondary storage device such as a hard disk. C program file names should end with the .c extension or save it directly.

Preprocessing and Compiling a C Program


Here you give the command to compile the program. The compiler translates the C program into machine language-code (also referred to as object code). In a C system, a preprocessor program executes automatically before the compiler’s translation phase begins.

The C preprocessor obeys special commands called preprocessor directives, which indicate that certain manipulations are to be performed on the program before compilation. These manipulations usually consist of including other files in the file to be compiled and performing various text replacements. The most common preprocessor directives will discussed soon.
  
The compiler translates the C program into machine-language code. A syntax error occurs when the compiler cannot recognize a statement because it violates the rules of the language. The compiler issues an error message to help you locate and fix the incorrect statement. The C Standard does not specify the wording for error messages issued by the compiler, so the error messages you see on your system may differ from those on other systems. Syntax errors are also called compile errors, or compile-time errors.

Source codes in C are saved with .C file extension. Header files or library files have the .H file extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and an executable .EXE file.




Linking


The next phase is called linking. C programs typically contain references to functions defined elsewhere, such as in the standard libraries or in the private libraries of groups of programmers working on a particular project. The object code produced by the C compiler typically contains “holes” due to these missing parts. A linker links the object code with the code for the missing functions to produce an executable image (with no missing pieces). Compile and link a program If the program compiles and links correctly, a file called .out is produced.

Loading


The next phase is called loading. Before a program can be executed, the program must first be placed in memory. This is done by the loader, which takes the executable image from disk and transfers it to memory. Additional components from shared libraries that support the program are also loaded.

Execution


Finally, the computer, under the control of its CPU, executes the program one instruction at a time. To load and execute the program on a Linux system, type ./a.out at the Linux prompt and press Enter.

No comments:

Post a Comment

Thank you for your Time. Keep Learning

Geeks4Coding

Contributors

Popular Posts