pardxa
December 8th, 2002, 07:21 AM
I am trying to keep all global variables in one .h file.here is a example like this:
// stdafx.h
#if !defined(AFX_STDAFX)
#define AFX_STDAFX
#include <stdio.h>
char word[20];
#endif
//main.cpp
#include "stdafx.h"
int main(int argc, char* argv[])
{
strcpy(word,"ok ,you r welcome",20);
printf(word);
return 0;
}
but the result like this:
Linking...
StdAfx.obj : error LNK2005: "char * word" (?word@@3PADA) already defined in console.obj
Debug/console.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
what should i do, if i intend to keep all global variables in a header file.
// stdafx.h
#if !defined(AFX_STDAFX)
#define AFX_STDAFX
#include <stdio.h>
char word[20];
#endif
//main.cpp
#include "stdafx.h"
int main(int argc, char* argv[])
{
strcpy(word,"ok ,you r welcome",20);
printf(word);
return 0;
}
but the result like this:
Linking...
StdAfx.obj : error LNK2005: "char * word" (?word@@3PADA) already defined in console.obj
Debug/console.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
what should i do, if i intend to keep all global variables in a header file.