Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does g++ compilation order matter?

Tags:

c++

g++

I noticed that I was able to compile a child class before a parent class with g++. Is there any need to compile in a specific order, with consideration to dependencies?

like image 953
Cryo Avatar asked Apr 10 '11 23:04

Cryo


People also ask

Does order of compilation matter?

Each . c file is a separate compilation unit which is compiled independently of other compilation units. So the compilation order does not matter. But: each .

What does G do in compiling?

(debug) Inserting the `g' flag tells the compiler to insert more information about the source code into the executable than it normally would.

How does Cpp compilation work?

Each C++ source file needs to be compiled into an object file. The object files resulting from the compilation of multiple source files are then linked into an executable, a shared library, or a static library (the last of these being just an archive of object files).

Can you compile header files?

Only those changed files need to be recompiled. Header files are not compiled directly, Instead, header files are included into other source files via #include .


2 Answers

In short: No!

Each C++ compilation unit (C++ source file) is compiled independently. Class inheritance etc is set up at runtime. This is why you can have base classes in separately maintained libraries that can be updated without forcing descendant classes to be recompiled, as long as the API and the ABI remains compatible.

like image 140
thkala Avatar answered Sep 25 '22 23:09

thkala


Linking order can matter; compilation order does not.

like image 34
ildjarn Avatar answered Sep 22 '22 23:09

ildjarn