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

  • Home
  • SEARCH
  • 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 8099489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:25:21+00:00 2026-06-05T22:25:21+00:00

I have 4 files (2 headers, and 2 code files). FileA.cpp, FileA.h, FileB.cpp, FileB.h

  • 0

I have 4 files (2 headers, and 2 code files).
FileA.cpp, FileA.h, FileB.cpp, FileB.h

FileA.cpp:

#include "FileA.h"

int main()
{
    hello();
    return 0;
}

void hello()
{
    //code here
}

FileA.h:

#ifndef FILEA_H_
#define FILEA_H_
#include "FileB.h"
void hello();

#endif /* FILEA_H_ */

FileB.cpp:

#include "FileB.h"

void world()
{
    //more code;
}

FileB.h:

#ifndef FILEB_H_
#define FILEB_H_

int wat;
void world();


#endif /* FILEB_H_ */

when I try to compile(with eclipse), I get ” multiple definition of `wat’ ”
And I don’t know why, it seems as it should work just fine.

  • 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-06-05T22:25:22+00:00Added an answer on June 5, 2026 at 10:25 pm

    I’m not going to include all of the details, but you define a global variable, wat twice in your compilation uint.

    To fix, use the following:

    FileB.h

    extern int wat;
    

    FileB.cpp

    int wat = 0;
    

    This (extern) tells the compile that the variable wat exists somewhere, and that it needs to find it on it’s own (in this case, it’s in FileB.cpp)

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

Sidebar

Related Questions

Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
I currently have a program where my main code is in a file main.cpp.
The Background I have the following source code #include <libubuntuone-1.0/u1-music-store.h> #include <libsyncdaemon-1.0/libsyncdaemon/libsyncdaemon.h> static void
I have the file long_arithm.cpp: #ifndef LONG_ARITHM.CPP #define LONG_ARITHM.CPP #include <iostream> #include <list> namespace
I have the simplest code that I want to separate in three files: Header
I have been seeing code like this usually in the start of header files:
I have a project folder with sources, headers, resources, etc. Most files are subject
I have three files: movie.h (header); movie.cpp (implementation file); lab9.cpp (driver file using movie
I have a program using 3 header files and 3 .cpp files in addition
Let's say I have the following code: // templateClass.h #ifndef TEMPLATE_CLASS_H #define TEMPLATE_CLASS_H template

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.