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 4106162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:20:27+00:00 2026-05-20T21:20:27+00:00

I have recently become aware that I have no idea, genericly speaking, how a

  • 0

I have recently become aware that I have no idea, genericly speaking, how a c/c++ compiler works. I will admit this initialy came from trying to understand header guards but came to the realization that I am lacking in how compiling works.

Take Visual C++ for instance; Theres the "Header Files" folder, the "Resources Files" folder, and "Source Files" folder. Is there any significance to the separation of these folders and what you put in them? To me, they are all source files. Take the code snippets:

Snippet 1

//a1.h
int r=4;

and

//a1.cpp
int b  //<--semicolon left out on purpose

and

//main.cpp
#include <iostream>
#include "a1.h"
void main()
{
   cout << r;
}

The compiler errors out saying "a1.cpp(3) : fatal error C1004: unexpected end-of-file found" where I would expect it wouldn’t because the a1.cpp file is not #included where the main method exists where in the next code snippet

Snippet 2

//a1.h
int r=4 //<--semicolon left out on purpose

and

//a1.cpp
int b = 4;  

and

//main.cpp
#include <iostream>
void main()
{
   cout << b;
}

Errors out because "main.cpp(6) : error C2065: ‘b’ : undeclared identifier". If you include the a1.cpp like so

Snippet 3

//a1.h
int r=4 //<--semicolon left out on purpose

and

//a1.cpp
int b = 4;  

and

//main.cpp
#include <iostream>
#include "a1.cpp"
void main()
{
   cout << b;
}

the compiler complains "a1.obj : error LNK2005: "int b" (?b@@3HA) already defined in main.obj". Both snippets 2 and 3 ignore the fact that int r = 4 does not have a semicolon missing as I suspect that it has something to do with its a xxxx.h file. If I remove the a1.cpp file from the project on snippet 1, then it compiles fine. Clearly what I have expected is not what I am getting. Theres plenty of books and tutorials on how to code in cpp, but not much in the way cpp handles files and source code in the complition process. What on earth is going on here?

  • 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-20T21:20:27+00:00Added an answer on May 20, 2026 at 9:20 pm

    Your questions aren’t really about the compiler, but about how your IDE is handling the entire build system. The build systems for most C/C++ projects compile each .c or .cpp file separately, and then link the resulting object files together into a final executable. In your case, your IDE is compiling any file you have in the project with a filename extension of .cpp and then linking the resulting objects. The behaviour you’re seeing can be explained as follows:

    1. a1.cpp is missing a ;, so when the IDE tries to compile that file, you get the error about ‘unexpected end of file’.

    2. b isn’t declared anywhere in the main.cpp compilation unit, so you get an error about an undefined identifier.

    3. b exists in both the main.cpp and a1.cpp compilation units (obviously in a1.cpp, and via your #include for main.cpp). Your IDE compiles both of those files – now a1.o and main.o each contain an object called b. When linking, you get a duplicate symbol error.

    The important point to take away here, which explains all of the behaviour you see, is that your IDE compiles every .cpp file – not just main.cpp and the files it includes – and then links the resulting objects.

    I recommend setting up a command-line test project with a makefile you create yourself – that will teach you all about the inner workings of build systems, and you can then apply that knowledge to the inner workings of your IDE.

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

Sidebar

Related Questions

I have recently become aware that our code has several implementations of a version
Recently, I have become increasingly familiar with Django. I have a new project that
I have recently found out that the future of Qt has become uncertain as
I have recently become interested in the field(s) of data mining and machine learning.
I have recently started to learn Objective-C and write my tests using OCUnit that
I have recently become an intern on a startup online classroom system. So now,
I have recently become a teaching assistant for a university course which primarily teaches
I recent came across Javascript templates and have become quite intrigued. I am building
I have recently become a T4MVC fanatic and now I seem incapable of using
I've recently become familiar with Reflection , and have been experimenting with it, especially

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.