为什么link 出现警告呢?

CppFile CppFile 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
警告如下
[Linker Warning] Public symbol '_ErrorMsgTable' defined in both module C:\CBUILDER6\PROJECTS\222\UNIT1.OBJ and C:\CBUILDER6\PROJECTS\222\UNIT2.OBJ


我写了一个测试用例

1.建立一个pub.h文件,内容如下



#ifndef __Pub__
#define __Pub__


typedef struct
{
char *RetCode;
char *ErrorMsg;
} Error_Msg_Table;

Error_Msg_Table ErrorMsgTable[] =
{
{
"111", "错误哦"
}


};
#endif



我是这样做的
1.建立2个窗体,unit1和unit2.
2.unit1.h中#include "pub.h" ,并在一个函数中这样使用, ErrorMsgTable[0].RetCode="111";


3.在unit2.cpp中包含unit1.h和unit2.h


然后编译,会出现上面的link 警告,为什么会重复呢?我不是在pub.h中使用了#ifndef __Pub__
#define __Pub__ 。。。这样的结构吗?应该不会重复的编译了啊?
...全文
评论 4
收藏 已收藏
分享
返回顶部
CppFile
C++ Builder 13,871 成员 102,696 内容