C/C++ header and implementation files: How do they work?

前端 未结 7 2060
执笔经年
执笔经年 2020-11-30 22:43

This is probably a stupid question, but I\'ve searched for quite a while now here and on the web and couldn\'t come up with a clear answer (did my due diligence goo

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 23:45

    As suggested in Matthieu M.'s comment, it is the linker job to find the right "function" at the right place. Compilation steps are, roughly:

    1. The compiler is invoked for each cpp file and translate it to an object file (binary code) with a symbol table which associates function name (names are mangled in c++) to their location in the object file.
    2. The linker is invoked only one time: whith every object file in parameter. It will resolve function call location from one object file to another thanks to symbol tables. One main() function MUST exist somewhere. Eventually a binary executable file is produced when the linker found everything it needs.

提交回复
热议问题