Overdue absences… Much of the content comes from chapter 7 of Understanding Computer Systems in Depth

It’s a really good book. I recommend it to everyone. What is written here is just a little overview. It is only superficial and needs further study in the future.

What is.h and.cpp? How to compile?

For slightly larger and more complex software, we would normally write the declaration in.h and then implement it in.cpp.

No matter how we write our.h, when we use it, we include it at the top of CPP.

What happens to the things that are included? Will be copied directly to the include location during preprocessing.

Wouldn’t that be the same as writing the declaration directly in the CPP?

Yes, this is the QWQ, but in the middle of the pre-processing step.

At this point, the.H mission is complete, he has nothing more to do.

This object file you’re talking about, what kind of thing is it?

ObjectFIle, ObjectFIle

There are several types of object files,.o,.so,.out.

O: Object Relocates the target file

It contains binary code, data, and can be merged with other relocatable object files to produce an executable object file

.out (or no suffix) : executable object file

It contains binary code, data, and can be copied directly to memory for execution

So SharedObject, also known as dynamic link library

So is a special relocatable object file that can be dynamically loaded into memory and linked at load/run time

A, static link library

How static linker works

  1. Symbol Resolution: Correlates references and definitions for each Symbol
  2. Relocation: CCL, AS generates code, data sections starting at address 0, and LD needs to associate the definition of each symbol with a memory location to relocate these sections. Finally, modify the reference so that the symbol definition points to the location of the memory.

.so, dynamic link library

  1. Relocate the text and data of each SO to some two memory segments;
  2. Relocate all references to libc.so, libfoofunc.so definition symbols in foo
  3. Finally, LD transfers control to Foo. From this point on, Foo’s position is fixed and does not change throughout the execution.