Why compile a + link when building C ++ code instead of creating an executable file directly

I was asked about this question, when the mentor of an entry-level programmer, I thought about this process of compiling + links, so official and ordinary that I never think about why.

One thing I could think of was to improve development productivity, but should there be other reasons related to the compiler?

+3
source share
5 answers

Efficiency. When you compile the program, you create an object file for each source file, if you change the source file, you only need to recompile this module and then reconnect (switching is cheap). If the compiler did everything in one pass, he would have to recompile everything for each change.

It also follows the unix philosophy of small programs that do one thing, so you have a preprocessor, compiler, linker, library creator. Now these steps can be different modes of the same tool.

, , , , , - , , info .

, , , , , .., !

+13

. , . , . , : , ( ), , , . . , .

+2

, , , 24 . . , " " , :

  • , , .

  • . Make , , ccdist.

, .

+2
source

What a great time to teach your protege the principle of one responsibility!

+2
source

Compiling the file changes the code to binary code that the computer can read. File binding tells the computer how to execute the command. Thus, it is impossible to create everything at once, without two steps.

-3
source

Source: https://habr.com/ru/post/1749618/


All Articles