c++ - What is the difference between 'compiling and linking' and just 'compiling' (with g++)? -


i'm new c++ , have been learning how create makefile , have noticed 1 of examples have (which has 'updating' changed files, , ignoring unchanged files) has following command:

# syscompiler set g++ .o:.cpp      $(syscompiler) -c $< 

according manual g++, compiles or assembles source files doesn't link them.

> -c compile or assemble source files, not link. linking stage not done. ultimate output in form of object file each source file. default, object file name source file made replacing suffix .c',.i', .s', etc., with.o'. unrecognized input files, not requiring compilation or assembly, ignored.

in other words, wondering 'not linking' means when comes compiling in c++?

the code of single c or c++ program may split among multiple c or c++ files. these files called translation units.

compiling transforms each translation unit special format representing binary code belongs single translation unit, along additional information connect multiple units together.

for example, 1 define function in 1 a.c file, , call b.c file. format places binary code of function a.o, , records @ location code of function starts. file b.c records references function b.o.

linking connects references b.o function a.o, producing final executable of program.

splitting translation process 2 stages, compilation , linking, done improve translation speed. when modify single file form set of dozen of files or so, 1 file needs compiled, while remaining .o files reused form previous translation.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -