fpub.h  //头#ifndef pub_file_h_abcd
#define pub_file_h_abcd class CPublic
{
private:
char AppPath[MAX_PATH];
char LogPath[MAX_PATH];
char AdoConnectString[MAX_PATH];
_ConnectionPtr Conn;
_RecordsetPtr rs; public:  //method
CPublic();
~CPublic(); void SysErrorMsg(int id, char *Buffer); char *GetConnectString();
};CPublic Pubs;   //全局类#end错误信息:
Linking...
CBCProgramDlg.obj : error LNK2005: "class CPublic  Pubs" (?Pubs@@3VCPublic@@A) already defined in CBCProgram.obj
fpub.obj : error LNK2005: "class CPublic  Pubs" (?Pubs@@3VCPublic@@A) already defined in CBCProgram.obj
MySocket.obj : error LNK2005: "class CPublic  Pubs" (?Pubs@@3VCPublic@@A) already defined in CBCProgram.obj
Debug/CBCProgram.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

解决方案 »

  1.   

    应该没有什么问题啊,在需要使用CPublic Pubs; 的地方使用extern导出就可以了啊
      

  2.   

    在源文件中定义,
    在头文件中可以extern CPublic Pubs;
      

  3.   

    end->endif
    link2005的msdn解决是
    To set this linker option in the Visual Studio development environment Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties. 
    Click the Linker folder. 
    Click the Command Line property page. 
    Type the option into the Additional Options box. 
      

  4.   

    因为你没有搞清楚声明与定义的区别!
    在头文件中:CPublic Pubs;   是定义一个对象,而不是声明一个对象!
    在头文件中一般都是声明,如声明类,宏等!因为你的语句是定义对象,所以只要有两个文件中包含了该头文件,那么就是定义了两次,即重定义!解决办法是全局变量在CPP文件中定义,在别的要使用的文件中extern一下就行了!还有什么不明白,可以继续问!
      

  5.   

    用extern的方法我已经试过了,只试了一下不行,就没有深入研究,上面的问题我已经在头文件中用
    #ifndef pub_file_h_abcd
    #define pub_file_h_abcd ...
    #endif
    这样预编译处理,不是如果包含过一次,就不再包含的吗?
      

  6.   

    你在使用的cpp文件里,包含这个头文件了吗?有基础包含头文件的地方你都包含了吗?
      

  7.   

    重复定义了.可以使用extern声明一下还有,#end -> #endif
      

  8.   

    同意andyfr1210(华仔) 所说的,全局变量要在CPP文件中定义,在别的要使用的文件中extern一下就行了!
      

  9.   

    全局变量放cpp吧,免得h文件重复包含了
      

  10.   

    同意楼上的,不如和C*** theApp;放在一起,以后也方便找~
      

  11.   

    在头文件里应该extern, 在用到这个变量的cpp里定义。
      

  12.   

    将工程下的Debug,Release目录删除,*.NCB,*.OPT,*.APS,*.CLW文件删除重新编译试试