为什么link 出现警告呢?

CppFile 2009-11-02 08:27:27
警告如下
[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__ 。。。这样的结构吗?应该不会重复的编译了啊?
...全文
115 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cppfile 的回复:]
为什么会重复定义呢?我不是用#ifndef __Pub__
  #define __Pub__ 。。。把代码包起来了吗?
[/Quote]
那个防止重复声明,防止不了重复定义.
CppFile 2009-11-02
  • 打赏
  • 举报
回复
为什么会重复定义呢?我不是用#ifndef __Pub__
#define __Pub__ 。。。把代码包起来了吗?
我不懂电脑 2009-11-02
  • 打赏
  • 举报
回复
_ErrorMsgTable这个变量在UNIT1和UNIT2.OB中定义了
  • 打赏
  • 举报
回复
ErrorMsgTable应该在cpp中定义, .h中用extern声明

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧