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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:44:55+00:00 2026-06-02T12:44:55+00:00

IN my C++ code I want to make use of a variable VarX in

  • 0

IN my C++ code I want to make use of a variable “VarX” in a file “B” which is actually modified in another file “A”.
So I had a look @ the following link & used extern concept.

How do I use extern to share variables between source files?

error LNK2005: “unsigned int VarX” (?VarX@@3IA) already defined in
***.obj.

My scenario is as follows:

File1.h
extern unsigned int VarX;

File2.cpp
#include File1.h
unsigned int VarX = 101;

File3.cpp
#include File1.h
unsigned int temp = VarX;

IMP NOTE: In the header file File1.h there are many other structure definitions and also many othe rdefinitions apart from the Extern definition.

Can someone help me in this. How shall I read the Value of VarX which is modified in File2.cpp in another File File3.cpp.

  • 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-02T12:45:06+00:00Added an answer on June 2, 2026 at 12:45 pm

    The problem isn’t accessibility, but a multiple definition. The error message is pretty clear, somewhere in the code you’re redefining VarX.

    Common causes can be:

    • invalid build – have you cleaned the build before compiling?
    • you have multiple unsigned int VarX = 101; or a unsigned int VarX; somewhere (in a header or an implementation file), without an extern declaration.
    • you #include "File2.cpp" somewhere in the code, causing it to be compiled multiple times.

    My bet is on the second possiblity.

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

Sidebar

Related Questions

I want to make a code that counts the click on the link which
I use PhpStorm. I want to make snippets of code and then assign shortcuts
For some MATLAB code that I want to make executable, I need the location
I have this code that I want to make point-free; (\k t -> chr
Want to code a key pad for an calculator. What I want to make
I want to make a code snippet database web application. Would the best way
i want to make a system call in my python code but the problem
I want to make sure the first 4 letters in a eight character code
I want to make this 1332251639632 to this 1332251639 I try this code, but
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,

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.