Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does the C++ compiler start?

If you have a c++ project with several source files and you hit compile, which file does the compiler start with?

I am asking cause I am having some #include-dependency issues on a library.

Compiler would be: VC2003.

like image 446
clamp Avatar asked Jun 30 '26 08:06

clamp


2 Answers

It should not be order-dependent. The only relevant steps are:

  1. Each compilation unit includes what it depends on, and should be compilable individually. This means, first, that each CPP file includes all the headers it depends on; and second, that each header should in turn include what it needs so that it can compile even if it is the first one to be compiled.
  2. A link step puts all the compiled object code together and builds the final binary.
like image 135
Daniel Daranas Avatar answered Jul 03 '26 12:07

Daniel Daranas


It should not matter which file it starts with, the linker resolves external references after all the files have been compiled

like image 20
Anders Avatar answered Jul 03 '26 11:07

Anders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!