链接错误:未解析的外部

时间:2015-10-26 12:41:27

标签: c++ oop graphics sdl-2

所以,我是C ++和SDL的新手......我得到了链接错误:(在SDL_Game.exe中,这些代码的编译版本)

LNK 1120 : Unresolved Externals

我也得到了这两个错误:

Error   2   error LNK2001: unresolved external symbol "public: static bool SDL_main::isRunning" (?isRunning@SDL_main@@2_NA) C:\Users\MyName\Desktop\SDL_Game\SDL_Game\Input.obj SDL_Game


Error   3   error LNK2001: unresolved external symbol "public: static bool SDL_main::isRunning" (?isRunning@SDL_main@@2_NA) C:\Users\MyName\Desktop\SDL_Game\SDL_Game\main.obj  SDL_Game

我的应用程序类型设置为控制台,因此不是问题。

  • 我可能做了一件非常愚蠢的事......

(注意:这里可能有很多错误,你已被警告过了......)

所以,这是我的源代码:

main.cpp:

#include "Graphics\Window.h"
#include "Input\Input.h"
#include <string>
#include <iostream>
#include <main.h>

void Debug(std::string text);

int main(int argc, char* argv[])
{
    main::isRunning = true;
    Window C_Window;
    Window window();
    Input input();

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        main::isRunning = false;
        std::cout << "SDL Video Initialization Failed : " << SDL_GetError() << std::endl;
        std::cout << "Press enter to quit..." << std::endl;
        system("PAUSE"); // Only works on windows.

    }
    else 
    {
        while (main::isRunning)
        {
            SDL_UpdateWindowSurface(C_Window.GetWindow());
        }
    }
    SDL_UpdateWindowSurface(C_Window.GetWindow());
    Debug("SDL_winsurupd called in main");
    system("PAUSE"); // Only works on windows.
    SDL_Quit();

    return 0;
}

void Debug(std::string text)
{
    std::cout << text << std::endl;
}

main::~main()
{

}

main.h:

#pragma once
#include <SDL.h>
#include <iostream>
#include <Graphics\Window.h>

class main
{
public:

    static bool isRunning;

    main();

    ~main();

private:



};

window.h中

#pragma once
#include <SDL.h>
#include <iostream>

class Window
{
public:

    Window();

    SDL_Window* GetWindow();

    ~Window();

private:

    SDL_Window* window = nullptr;

};

Window.cpp

#include "Window.h"


Window::Window()
{
    window = SDL_CreateWindow("Engine Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
    if (window == NULL)
    {
        std::cout << "Window Creation Failed : " << SDL_GetError() << std::endl;
        system("PAUSE"); // Only works in windows.
    }
    else 
    {
        SDL_UpdateWindowSurface(window);
    }
}

SDL_Window* Window::GetWindow()
{
    if (window != NULL)
    {
        return window;
    }
    else 
    {
        std::cout << "Could not get window since it was not created yet." << std::endl;
        system("PAUSE");
    }
}


Window::~Window()
{
}

Input.h

#pragma once
#include <SDL.h>
#include <iostream>
#include <Graphics\Window.h>

class Input
{
public:

    Input();

    ~Input();

private:

    SDL_Event evnt;

};

Input.cpp

#include "Input.h"
#include <main.h>


Input::Input()
{
    while (main::isRunning)
    {
        while (SDL_PollEvent(&evnt) != 0)
        {
            if (evnt.type == SDL_QUIT) {
                SDL_Quit();
            }
        }
    }
}


Input::~Input()
{

}

0 个答案:

没有答案