为何main()里定义的const对象不能为其他文件所用解决方案

为何main()里定义的const对象不能为其他文件所用
C/C++ code

//a.h
#ifndef _A_H_
#define _A_H_

#include "b.h"

extern const int ArrayCount;

typedef struct
{
    int *a;   
    int data;      
}DataType;

extern void Init( DataType *G );

//a.cpp
#include "a.h"

void Init( DataType *G )
{
    G->data = 0;

    G->a = new int [ArrayCount];

    for ( int i = 0; i < ArrayCount; i++ )
    {
        G->a[i] = i;
    }
}

//b.h
#ifndef _B_H_
#define _B_H_

extern const int ArrayCount;

extern void Function( int &val2 );

#endif

//b.cpp
#include "b.h"

void Function( int &val2 )
{
    int x = 16;
    x *= x;

    val2 = x;
}

//main.cpp
#include <cstdio>
#include "a.h"
#include "b.h"

int main( void )
{
    int nVal = 0;

    Function( nVal );

    const int ArrayCount = 10;

    DataType x;

    Init(&x);

    for ( int i = 0; i < ArrayCount; i++ )
    {
        printf( "%d ", x.a[i] );
    }

    printf("\n");
    return 1;
    
}


编译连接报错如下:
1>a.obj : error LNK2001: unresolved external symbol "int const ArrayCount" (?ArrayCount@@3HB)
1>E:\Computer Vision\OpenCV2\Debug\OpenCV2.exe : fatal error LNK1120: 1 unresolved externals
请问下这是为什么呢

------解决方案--------------------
你这里是局部变量定义的。作用域当然受限。 而且即使是全局变量 const 修饰的全局变量默认的链接属性是internal必须在定义的时候用extern 来显示声明
------解决方案--------------------
因为你在main里定义的是局部变量

把const int ArrayCount = 10 移到int main前面才是全局
------解决方案--------------------
const本身就是个本地限制符
可以在头文件里面定义 然后要用的地方include头文件就行
------解决方案--------------------
没有其它办法,既然你申明为const,那就没法给它一个变量值。
------解决方案--------------------
不要纠结各种常量了,这个世界上唯一不变的就是变化。用API WriteProcessMemory还能修改正运行的其它进程的内存里面的所谓常量呢!