How does C++ compilation happen?

There are a number of good text books on compilers (and building them) - I have at least 3 or 4 on my bookshelf; however, this is not a beginner-level subject. There is some good documentation on the GNU web site, especially as related to the GCC (GNU Compiler Collection) tool set. Go to www.gnu.org for more details: http://www.gnu.org/software/gcc/

I am looking for a kinda overly simplified version. Something about a paragraph long.

Simple version using static libraries

The compiler is presented with a list of source files to compile (i.e. the ones usually named *.cpp)

For each of those:

  1. The preprocessor goes through and handles the #defines, #includes, etc, changing each individual *.cpp file into a slightly different *.cpp file
  2. The compiler turns each slightly different *.cpp file into a single object file

The linker is now presented with a list of those object files, and also a list of any other object files (i.e. libraries) that it is to work with.

The linker joins all the object files into a single new object file with some extra administrative bits (if it is making a library), or a single executable. It makes sure that every function used does actually have an implementation somewhere in those object files or existing libraries (if it can't find one, you get the famous undefined reference error).

So are the Object filesin assebmbly or what is the form they use?

if compiler converts the source code to the object file, does the Linker convert the Object file to the native machine code?

So are the Object filesin assebmbly or what is the form they use?

Machine code. Raw instructions for the processor. Not assembly.

does the Linker convert the Object file to the native machine code?

No, the compiler did that. Object files are machine code and some housekeeping information describing the contents so that when the linker has to actually use the object file, it knows what it's got.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.