Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why it's important to separate compilation and linking processes in C?

I've been programming in C for a while and i wondered why is important to separate this processes (Compile and Linking)?

Can someone explain please?

like image 789
Luca Avatar asked Jul 05 '16 09:07

Luca


People also ask

How does compilation/linking process work in C/C++?

How does the compilation/linking process work in C/C++? Preprocessing − In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. It handles preprocessing directives like #include, #define, etc.

What is compilation in C++?

Compilation − The compilation takes place on the preprocessed files. The compiler parses the pure C++ source code and converts it into assembly code. This in turn calls the assembler that converts the assembly code to machine code (binary) as Object files. These Object files can refer to symbols that are not defined.

Why are there separate compilation and linking steps for each function?

You might ask why there are separate compilation and linking steps. First, it's probably easier to implement things that way. The compiler does its thing, and the linker does its thing -- by keeping the functions separate, the complexity of the program is reduced.

Is it possible to link functions at the time of compilation?

It depends on the compiler, theoretically yes. Linking means bundling together object files and object Files comes only after compilation. It depends on your definition of "at the time of". You need to have individual functions compiled before you can link the call of one function to another - so it has to be sequential.


1 Answers

It is useful in order to decrease rebuilt time. If you change just one source file - it is often no need to recompile whole project but only one or few files.

like image 74
Sergio Avatar answered Nov 15 '22 01:11

Sergio