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.
#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.
在头文件中可以extern CPublic Pubs;
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.
在头文件中:CPublic Pubs; 是定义一个对象,而不是声明一个对象!
在头文件中一般都是声明,如声明类,宏等!因为你的语句是定义对象,所以只要有两个文件中包含了该头文件,那么就是定义了两次,即重定义!解决办法是全局变量在CPP文件中定义,在别的要使用的文件中extern一下就行了!还有什么不明白,可以继续问!
#ifndef pub_file_h_abcd
#define pub_file_h_abcd ...
#endif
这样预编译处理,不是如果包含过一次,就不再包含的吗?