注册 登录
编程论坛 C++教室

大家帮忙解释一下,新

xiangz9025 发布于 2007-12-29 16:26, 885 次点击
我的程序是如下形状:一个头文件.h,一个主函数.cpp,一个操作函数.cpp。操作函数包含头文件,然后主函数包含操作函数.cpp。运行时出现错误:

错误症状:

Linking...
xz.obj : error LNK2005: "public: __thiscall XZ::XZ(void)" (??0XZ@@QAE@XZ) already defined in xzmain.obj
xz.obj : error LNK2005: "public: void __thiscall XZ::pdc(void)" (?pdc@XZ@@QAEXXZ) already defined in xzmain.obj
xz.obj : error LNK2005: "public: void __thiscall XZ::pcd(void)" (?pcd@XZ@@QAEXXZ) already defined in xzmain.obj
xz.obj : error LNK2005: "public: void __thiscall XZ::pzf(void)" (?pzf@XZ@@QAEXXZ) already defined in xzmain.obj
xz.obj : error LNK2005: "public: __thiscall XZ::~XZ(void)" (??1XZ@@QAE@XZ) already defined in xzmain.obj
Debug/xzmain.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.

解决方案一:

把主函数所包含的操作函数.cpp,改为头文件.h,然后就可以解决如上错误。

解决方案二:

重新打开编译器,重新打开刚才的文件,先打开主函数.cpp,然后编译运行,打开Fileview,其中有一个external dependencies,把头文件.h,和操作函数.cpp添加到这里,这样再编译运行主函数.cpp,程序运行成功!



我也读到相同的问题,我这是在网上搜到的,确实是可以的,但不明白为什么会是这样,因为有时是好的!请各位帮忙解释一下,尤其第二种怎么加,我怎们加不上啊!
3 回复
#2
xiangz90252007-12-30 12:17
咋没有回答的呢?!自己给自己顶一下!
大师很多!望赐教!
#3
雨中飞燕2007-12-30 12:30
在偶群里已经给你讲了,不再多说
#4
hero20072007-12-30 15:06
有群么,我要加
1