您好,我的 IDE Visual Studio 2012 有问题。我已经开始学习 SDL,所以对它还很陌生,我正在尝试在使用 SDL 时应用良好的结构。当我开始使用带有类的 SDL 时,问题就出现了。如果我在 main 中输入所有内容,它就可以正常工作。我不知道哪里做错了,你能帮我看看错误吗
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: _exit already defined in LIBCMT.lib (crt0dat.obj)
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: _fclose already defined in LIBCMT.lib(fclose.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Users\User\documents\visual studio 2012\Projects\Nebula\Debug\Nebula.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这是我的代码,如果有问题
主要
#include <SDL.h>
#include "System.h"
int main(int argc, char* argv[])
{
System RedObject;
RedObject.SetUp();
SDL_Quit();
return 0;
}
第二个文件。
#include "System.h"
System::System()
{
}
System::~System()
{
}
void System::SetUp()
{
SDL_Init(SDL_INIT_EVERYTHING); // The SDL Set up bit.
SDL_Surface * screen;
SDL_WM_SetCaption("Window Name", NULL);
fullscreen = false;
if(fullscreen == true)
{
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE | SDL_FULLSCREEN);
}
else
{
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
}
bool running = true;
while(running)
{
SDL_Event Event;
while(SDL_PollEvent(&Event))
{
switch(Event.type)
case SDL_QUIT:
running = false;
break;
}
SDL_Flip(screen);
}
}
第二个文件头:
#ifndef SYSTEM_H
#define SYSTEM_H
#include <SDL.h>
class System
{
private:
int SHeight, SLenght;
bool fullscreen;
public:
System();
~System();
void SetUp();
};
#endif
我还设置了 IDE 代码生成器以在多线程 DLL (/MD) 上运行,我不知道这是否是问题所在。抱歉,如果这个问题已经得到回答,我可以找到答案。提前谢谢你。
最佳答案
我认为问题在于 Visual Studio 的 .NET Framework 使用 System
作为根级命名空间,因此您可能遇到了名称冲突。尝试将类命名为 System 以外的名称。
关于c++ - 带类的 SDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14656452/