file1.h
- Код: выделить все
#pragma once
#if !defined(FILE1_INCLUDED_)
#define FILE1_INCLUDED_
char
*file1Var1 = "string 1",
*file1Var2 = "string 2";
#define FILE1_MACRO1 "macro 1"
#define FILE1_MACRO2 "macro 2"
int file1func1(int arg1);
#endif // !defined(FILE1_INCLUDED_)
file1.cpp:
- Код: выделить все
#include <windows.h>
#include "file1.h"
int file1func1(int arg1){
return MessageBox(0, FILE1_MACRO1, file1Var2, MB_OK | MB_ICONHAND);
}
main.cpp:
- Код: выделить все
#include <windows.h>
#include "file1.h"
...
При компиляции под Visual C++ 6.0 возникают ошибки:
file1.obj : error LNK2005: "char * file1Var2" (?file1Var2@@3PADA) already defined in main.obj
file1.obj : error LNK2005: "char * file1Var1" (?file1Var1@@3PADA) already defined in main.obj
Debug/mytemplate.exe : fatal error LNK1169: one or more multiply defined symbols found
Кто-нибудь может объяснить, в чем тут дело?