我从编译器收到此错误:
1>Linking...
1>main.obj : error LNK2005: "int g_win_flags" (?g_win_flags@@3HA) already defined in init.obj
1>main.obj : error LNK2005: "struct SDL_Surface * g_screen" (?g_screen@@3PAUSDL_Surface@@A) already defined in init.obj
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>.\Debug\Heroes are back!.exe : fatal error LNK1169: one or more multiply defined symbols found
看起来 g_win_flags 和 g_screen 被包含了两次,但我不明白为什么。这是来源:
主文件
#include <iostream>
#include "dec.h"
#include "init.h"
int main(int argc, char *argv[]){
init();
return 0;
}
十二月
#ifndef DEC_H
#define DEC_H
#include <SDL.h>
#include <iostream>
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
using namespace std;
int g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
SDL_Surface *g_screen = NULL;
#endif
初始化.h
#ifndef INIT_H
#define INIT_H
bool init();
#endif
初始化文件
#include "dec.h"
bool init(){
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) == -1){
cerr << "Unable to initialize SDL" << endl;
return false;
}
g_screen = SDL_SetVideoMode(640, 480, 0, g_win_flags);
return true;
}
有人可以帮忙吗?在此先感谢,祝您有美好的一天:)