After writing C program when we compile and execute our program, there are various types of files are created. You can refer through Compiling a C program:- Behind the Scenes and How does a C program executes? for better understanding.
Below are the points followed when every C file is compiled:
- Every .h header file pre-compiles with it’s corresponding .c file and creates a header object file(.o file).
- Before compiling our main.c file it first go through the pre-processor, then compiler compiles it into assembler and creates object file (main.o).
- Then linker link the main.o with required header objects and libraries and creates a executable file (program.exe).
- Here is the list of files that are created:
- Source file(.c): These files contain function definitions, and the entire program logics, these files are human readable and by convention their names end with .c .
- Header file(.h): These files contain function prototypes and various pre-processor statements. They are used to allow source code files to access externally-defined functions and by convention their names end with .c.
- Object file(.o): These files are produced as the output of the compiler. They consist of function definitions in binary form, but they are not executable by themselves and by convention their names end with .c.
- Binary executables file(.exe): These files are produced as the output of a program called a “linker“. The linker links together a number of object files to produce a binary file that can be directly executed. It contains symbols that the linker can extract from the archive and insert into an executable as it is being built. And by convention their names end with .exe in windows.
- Dynamic Library file(.so, .dylib, .dll): A dynamic library (.so files for most POSIX systems, .dylib for OSX and .dll files for Windows) is dynamically linked at runtime by the program. These are also sometimes referred to as shared libraries because one library image can be shared by many programs. Dynamic libraries have the advantage of taking up less disk space if more than one application is using the library. Also, they allow library updates (bug fixes) without having to rebuild executables. And by convention .dll is used for their naming in windows, and .so is used in MacBook and .dylib is used in OSX.
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.