C/C++ Compilation of a header file in c++

  • Thread starter Thread starter krishna mohan
  • Start date Start date
  • Tags Tags
    C++ File
Click For Summary
When using the #include directive in C++, the header file's content is copied into the main program's source file before compilation. This means that the header file does not need to be compiled separately; it is compiled together with the main program. This process simplifies the compilation of programs that rely on multiple header files, as they are integrated into the source file during the compilation stage.
krishna mohan
Messages
114
Reaction score
0
Hi..am just learning c++...i have a doubt..

Suppose you have a header file and you include it in your main program by using the #include directive..then do you have to compile the header file separately? Or does it get compiled with the main program?
 
Technology news on Phys.org
krishna mohan said:
Or does it get compiled with the main program?
Yes, all the #include does is copy the text of the header file into the .cpp file before passing it to the compiler
 
I guess your yes means that one does not have to compile a header file separately...and it gets compiled with the main program..?
 
I understand..thank you..
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
81
Views
7K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 29 ·
Replies
29
Views
3K
Replies
6
Views
2K