-1

So I'm just trying to set up a game loop and window, but it won't even start with a blank screen. When I run it, it gives me an error every time I try to use any function from SDL. I have the .dll in the same folder as the project files and in the Debug folder. I'm pretty sure I have them linked in the project properties, too, but I don't know. When I'm in visual studio, I can hover over the functions and it has the declarations of them (I think)

SDL2\include is in VC++ Directories -> Include Directories

SDL2\lib\x64 is in VC++ Directories -> Library Directories

SDL2\include is also in C/C++ -> General -> Additional Include Directories

SDL2\lib\x64 is also in Linker -> General -> Additional Library Directories

SDL.lib and SDLmain.lib are both in Linker -> Input -> Additional Dependencies

edit: forgot to show project properties

This is Game.hpp

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

class Game 
{

public:
    Game();
    ~Game();

    void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
    
    void handleEvents();
    void update();
    void render();
    void clean();

    bool running() { return isRunning; }

private:
    int cnt = 0;
    bool isRunning;
    SDL_Window *window;
    SDL_Renderer *renderer;
};

This is Game.cpp

#include "Game.hpp"

Game::Game()
{}
Game::~Game()
{}

void Game::init(const char *title, int xpos, int ypos, int width, int height, bool fullscreen)
{

    int flags = 0;
    if (fullscreen) 
    { 
        flags = SDL_WINDOW_FULLSCREEN;
    }

    if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
    {
        std::cout << "Subsystems initialized" << std::endl;

        window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
        if (window)
        {
            std::cout << "Window created" << std::endl;
        }

        renderer = SDL_CreateRenderer(window, -1, 0);
        if (renderer)
        {
            SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
            std::cout << "Renderer created" << std::endl;
        }

        isRunning = true;
    } else {
        isRunning = false;
    }
}

void Game::handleEvents()
{
    SDL_Event event;
    SDL_PollEvent(&event);
    switch (event.type)
    {
        case SDL_QUIT:
            isRunning = false;
            break;
        default:
            break;
    }
}

void Game::update()
{
    cnt++;
    std::cout << cnt << std::endl;
}

void Game::render()
{
    SDL_RenderClear(renderer);
    //add stuff to render

    SDL_RenderPresent(renderer);
}

void Game::clean()
{
    SDL_DestroyWindow(window);
    SDL_DestroyRenderer(renderer);
    SDL_Quit();
    std::cout << "Game cleaned" << std::endl;
}

And this is main.cpp

#include "Game.hpp"

Game *game = nullptr;

int main(int argc, char *argv[]) {

    game = new Game();

    game->init("Maxgame", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);

    while (game->running()) {

        game->handleEvents();
        game->update();
        game->render();

    }

    game->clean();

    return 0;
}

And these are the errors I'm getting.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Max
  • 1
  • 2
  • https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Jesper Juhl Jul 20 '20 at 20:37
  • Evidence would seem to indicate that you don't have them linked properly in the project properties. To help further you're going to have to say what project properties you have set. – john Jul 20 '20 at 20:37
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jul 20 '20 at 20:38
  • 2
    The library is 64-bit, but you're building a 32-bit target. – molbdnilo Jul 20 '20 at 20:39
  • OK looking closer the problem is that you have a 64 bit library being linked with a 32 bit program. (see the warnings at the end). That doesn't work. – john Jul 20 '20 at 20:39
  • 1
    The hovering info in VS only depends on the headers and doesn't care about libraries. – molbdnilo Jul 20 '20 at 20:40
  • Switch from Win32 to x64 in on the toolbar. – drescherjm Jul 20 '20 at 20:42

1 Answers1

0

You could set Linker -> Advanced -> Target Machine -> MachineX64 in Properties. enter image description here

Barrnet Chou
  • 1,738
  • 1
  • 4
  • 7