Basic stucture of a C/C++ project (header files and cpp files) -


this brain-dead newbie question, here goes:

what determines files included in c/c++ project?

my understanding compiler starts file has main() in , file contain #include's various h files contain #include's other h files , on until included in project.

my questions:

what relationship between h files , cpp files of same name? mean, of course understand code-wise need each other , cpp file (almost always?) #include's h file, compiler's point of view important them have same names or convention? can include cpp files without corresponding h files?

also, when project built , linked, how know cpp/h files build object files for? start @ cpp file "main()" in , keep going through #include's until has needs , build of that, or build user specifies in makefile or in ide project file?

finally, when linker comes around , links object code make executable, there special order arranges in?

any help, hints, explanations appreciated.. thanks!

--r

think of files easy way split code make both more reusable , more maintainable.

you can put entire application in 1 big honking source file may find file rather big, leading compiler complaining (or @ least taking long time compile it).

typically hive off part of application (such generic database access layer) separate source file such db.cpp , create db.h file api. file isn't used db.cpp used other files need call functions in db.cpp. can included in db.cpp tends published information db code.

as how environment figures out things compile/link: tend have project of sort (makefile, ide project file, etc) lists programs want compile (usually not header files).

the environment compile each source file has been told produce object file - part of process incorporating included header files each source file, make compilation or translation unit - unit source file included header files incorporated @ point #include was.

the environment link object files form executable. keep in mind there variations on process such late (dynamic) linking. see here description of this.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -