Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1958252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:17:11+00:00 2026-05-17T08:17:11+00:00

This is a brain-dead newbie question, but here goes: What determines what files get

  • 0

This is a brain-dead newbie question, but here goes:

What determines what files get included in a C/C++ project?

My understanding is that the compiler starts with the file that has main() in it and that file will contain #include’s to get various h files which contain #include’s to 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 of the same name? I mean, of course I understand that code-wise they need each other and the cpp file always (almost always?) #include’s the h file, but from the compiler’s point of view is it important for them to have the same names or is this all just a convention? Can I include extra cpp files without corresponding h files?

Also, when the project is built and linked, how does it know which cpp/h files to build object files for? Will it just start at the cpp file with “main()” in it and keep going through #include’s until it has everything it needs and build all of that, or does it just build everything that a user specifies in the makefile or in the IDE project file?

Finally, when the linker finally comes around and links all the object code to make an executable, is there a special order it arranges everything in?

Any help, hints, explanations appreciated..
Thanks!

–R

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T08:17:12+00:00Added an answer on May 17, 2026 at 8:17 am

    Think of files as just an easy way to split up your code to make it both more reusable and more maintainable.

    You can just as easily put an entire application in one big honking source file but you may find that the file will get rather big, leading to the compiler complaining about it (or at least taking a long time to compile it).

    Typically you would hive off a part of your application (such as a generic database access layer) into a separate source file such as db.cpp and create a db.h file with its API. This file isn’t so much used by db.cpp as it is used by all the other files that need to call the functions in db.cpp. It can be included in db.cpp but it tends to be mostly published information about the db code.

    As to how an environment figures out which things to compile/link: you tend to have a project of some sort (makefile, IDE project file, etc) which lists all the programs that you want to compile (usually not header files).

    The environment will compile each source file that it has been told about to produce an object file – part of this process is incorporating the included header files into each source file, to make a compilation or translation unit – this unit is basically the source file with the included header files incorporated at the point where the #include was.

    The environment will then link all the object files to form an executable. Keep in mind there are variations on this process such as late (dynamic) linking. See here for a description of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry folks, I must be brain-dead or something but I can't get the styling
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This is my first post here and I wanted to get some input from
I am going brain dead on this; I have several List' defined, based on
a brain dead third party program I'm forced to use determines how to treat
Had a coworker ask me this, and in my brain befuddled state I didn't
This is a bit of a long shot, but if anyone can figure it
This is kinda oddball, but I was poking around with the GNU assembler today
When writing web apps in Python, it's brain dead easy to run a development

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.