2

Hello am having a problem with my IDE Visual Studio 2012. I have started to learn SDL so am quite new to it and I am trying apply good structure when using SDL. The problems lays when I start using SDL with classes. It works fine if I type everything in main. I don't know what am doing wrong can you help here are the errors

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 ==========

Here is my code if there is something wrong

Main

#include <SDL.h>
#include "System.h"

int main(int argc, char* argv[])
{
    System RedObject;
    RedObject.SetUp();

    SDL_Quit();
    return 0;
}

Second file.

#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);
    }
}

Second Files Header:

#ifndef SYSTEM_H
#define SYSTEM_H

#include <SDL.h>

class System
{
    private:
        int SHeight, SLenght;
        bool fullscreen;

    public:
        System();
        ~System();
        void SetUp();
};

#endif

Also I have set up the IDE code generator to run on Multi-threaded DLL (/MD) I don't know if that is the problem. Sorry if this question has been already answered I could find an answer. Thank you in advance.

4

2 回答 2

0

我认为问题在于 Visual Studio 的 .NET FrameworkSystem用作根级命名空间,因此您可能会遇到名称冲突。尝试将您的班级命名为 System.

于 2013-02-01T23:38:11.110 回答
0

我想到了!当您使用 SDL 构建对象时会出现此问题,并且存在两个库的冲突,您需要忽略其中一个。您需要忽略 LIBCMT.lib。如果您不知道如何操作,请按以下步骤操作:

  1. 打开项目的属性页。

  2. 单击链接器文件夹。

  3. 单击输入页面。

  4. 选择忽略特定默认库并进入编辑并放入 LIBCMT.lib 按确定然后应用设置,你应该很高兴。

我希望这可以为您节省几天的痛苦:)

于 2013-02-03T11:02:07.697 回答