链接器工具错误 LNK2004

“target”的 gp 相对链接地址信息溢出;短节“section”太大或超出范围。

该部分太大。

若要解决此错误,请减少短节的大小,方法是通过 #pragma 节(“.sectionname”、读取、写入、长节) 显式将数据放入长节,或者在数据定义和声明上使用 __declspec(allocate(".sectionname"))。 例如,

#pragma section(".data$mylong", read, write, long)
__declspec(allocate(".data$mylong"))
char    rg0[1] = { 1 };
char    rg1[2] = { 1 };
char    rg2[4] = { 1 };
char    rg3[8] = { 1 };
char    rg4[16] = { 1 };
char    rg5[32] = { 1 };

还可以将逻辑分组的数据移到其自身结构中,该结构将是大于 8 个字节的数据集合,编译器将在长数据部分中分配这些数据。 例如,

// from this...
int     w1  = 23;
int     w2 = 46;
int     w3 = 23*3;
int     w4 = 23*4;

// to this...
struct X {
    int     w1;
    int     w2;
    int     w3;
    int     w4;
} x  = { 23, 23*2, 23*3, 23*4 };

该错误之后为致命错误 LNK1165