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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:57:14+00:00 2026-06-18T21:57:14+00:00

Compiler : MS VS 2010 In my program below, I am declaring A_array as

  • 0

Compiler : MS VS 2010

In my program below, I am declaring A_array as extern (telling it the compiler it will be defined somewhere) and defining it in A.cpp.

However I am getting a linker error. Even though A.cpp compiled fine which means A_array should have been allocated memory and be present. What could be causing this issue?

Note: I have searched SO for the linker error code and I still could not find the precise reason for this error.

A.h
----------------------
#ifndef INC_A_H
#define INC_A_H
extern const int A_array[];
#endif
----------------------

A.cpp
----------------------
const int A_array[] = {10, 20, 30};
----------------------

B.cpp
----------------------
#include <iostream>
#include "A.h"

int main()
{
    for(int i=0; i<3; i++)
    {
        std::cout << A_array[i] <<"\n";
    }
    int x;
    std::cin >> x;
    return 0;
}
----------------------

Output:

1>ClCompile:
1>  B.cpp
1>  A.cpp
1>  Generating Code...
1>B.obj : error LNK2001: unresolved external symbol "int const * const A_array" (?A_array@@3QBHB)
1>Visual Studio 2010\Projects\test_extern\Debug\test_extern.exe : fatal error LNK1120: 1 unresolved externals

Update – 1:

When I include A.h in A.cpp the code compiles, links and works fine. Can someone explain why this is inclusion is need in A.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-18T21:57:15+00:00Added an answer on June 18, 2026 at 9:57 pm

    The problem is that you have a (slightly incorrect) forward declaration in the header file.

    The type of const int A_array[] = {10, 20, 30}; is an array or length 3.

    The type of const int A_array[] is int pointer or array of undefined length (it can’t know the length of the array yet).

    Since these definitions don’t match up exactly, the compiler will not know they are the same, unless you include A.h in A.cpp, since then both the definition and declaration will be in the same file and the compiler will link them.

    Making the declaration in A.h extern const int A_array[3] should work. Though including A.h in A.cpp would be more correct.

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

Sidebar

Related Questions

I have compiled this using Visual Studio 2010 compiler and it has compiler error
My problem is MSVS 2010 C++ compiler is generating code in a way after
Is there a way to force C# compiler, visual studio 2010, to call a
I loaded up the .net 3.5 FastMember from http://code.google.com/p/fast-member/source/checkout in VS 2010. The compiler
This code compiled properly on Visual Studio 2010 on Windows, but I'm getting this
I use Visual Studio 2010 to program in C. When the debugger meets an
The output from the following program is: Non-Static Static Non-Static Is this a compiler
I am trying to make my program written in Visual C# 2010 work on
[Replaced code by a complete program and versions update] The code below fails under
The question is how to configure in C++ Builder 2010 compiler and debug option

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.