The basic structure of a C / C ++ project (header files and cpp files)

This is a question new to the brain, but it says:

What determines which files will be included in a C / C ++ project?

I understand that the compiler starts with a file with main () in it, and this file will contain #include to get different h files containing #include for other h files, and so on, until everything is included in the project.

My questions:

What is the relationship between h files and cpp files with the same name? I mean, of course, I understand that according to the code they need each other, and the cpp file is always (almost always?) #Include h file, but from the point of view of the compiler it is important that they have the same name or is it just a convention ? Is it possible to add additional cpp files without corresponding h files?

Also, when a project is built and linked, how does it know which cpp / h files to create object files? Will it just run in the cpp file with "main ()" in it and continue to go through #include until it gets everything that it needs and builds it all, or just build everything that the user points to make file or to IDE project file?

Finally, when the linker finally arrives and links the entire object code to make the executable, is there a special order that it arranges everything in?

Any help, tips, explanations appreciated. Thank!

- R

+3
source share
4 answers

, , .

, , , , (, , ).

, (, ) , db.cpp, db.h API. db.cpp, , db.cpp. db.cpp, db.

, , /: - (makefile, IDE ..), , ( ).

, . , - , , #include.

. , , () . . .

+1

, , , . , , , . , , h cpp . cpp h , cpp - h , , , .

0

... , - - , .

, (, ), , , malloc(), socket(), file(), write() .., . , , new iostream.

, , , , , , , - , .

++ ( , ) , include cpp , , - , , .

, ; , .

(cpp) -, , , , , , , , -, , , . ( , cpp , , , . , , cpp std::string, , , ).

Implementation files may include other implementation files, but this would not be consistent with the general compilation division described above, therefore they confuse people who are used to this convention.

0
source

Source: https://habr.com/ru/post/1768356/


All Articles