您的位置:首页 > 编程语言 > C语言/C++

C++经典错误 already defined in *****.obj 解决方法

2010-11-02 21:17 274 查看
我的程序是如下形状:一个头文件.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,程序运行成功!





文章转自:http://hi.baidu.com/3512/blog/item/d568bc340c002cb4d0a2d3d6.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐