0

I recently wanted to start learning SDL2 and followed codergophers installation tutorial on youtube. However I ran into this error for some reason

(.text+0x49): undefined reference to `SDL_CreateWindow'

(.text+0x9b): undefined reference to `SDL_CreateRenderer'

This is my MakeFile (in all honesty I don't fully understand a whole lot of whats going on in the MakeFile so please correct me if im making some blatant mistake)

all:
    g++ -Iinclude -Iinclude/SDL2 -Iinclude/headers -I C:/SDL2-w64/include -Llib -o Main src/*.cpp -lmingw32 -lSDL2main  -lSDL2 -lSDL2_image -LC:/SDL2-w64/lib

and my file tree is

enter image description here

Where SDL2 contains the header files for SDL_Image.h and SDL.h and a whole bunch more. I also have a copy of x86_64-w64-mingw32 on my C drive under the name of SDL2-w64.

My code as for now is as follow:

src/main.cpp

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>

#include "headers/RenderWindow.hpp"

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

    RenderWindow window("Test" , 1280 , 720);

    return 0;
}

src/renderwindow.cpp

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

#include "headers/RenderWindow.hpp"
#include <iostream>

RenderWindow::RenderWindow(const char* title, int w , int h)
    :window(NULL) , renderer(NULL)
{
    window = SDL_CreateWindow(title , SDL_WINDOWPOS_UNDEFINED , SDL_WINDOWPOS_UNDEFINED , w , h , SDL_WINDOW_SHOWN);

    if(window == NULL)
    {
        std::cout << "Window failed to init. Error" << std::endl;
    }

    renderer = SDL_CreateRenderer(window , -1 ,SDL_RENDERER_ACCELERATED);
}

include/headers/RenderWindow.hpp

#pragma one
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

class RenderWindow
{
public:
    RenderWindow(const char* title , int w, int h);
private:
    SDL_Window* window;
    SDL_Renderer* renderer;

};

Again thank you so much for reading through all this. I spent a long time debugging this so I apologise in advance if I'm making some obvious blunder. Please feel free to ask any more follow up questions if the information provided is not necessary. Thank you :)

Recondit
  • 114
  • 9
  • You probably want `-LC:/SDL2-w64/lib` before any of the attempts to libk libraries in that directory. What is the process you are using to compile this? Are you sure the makefile is being used? – Retired Ninja Jun 13 '23 at 00:06
  • Refer to [How do I use SDL2 in my programs correctly?](https://stackoverflow.com/questions/64396979/how-do-i-use-sdl2-in-my-programs-correctly), it has everything you need to know. Probably an x32 SDL2 with an x64 compiler or vice versa. Also note that `SDL_MAIN_HANDLED` is bad and shouldn't be used. – HolyBlackCat Jun 13 '23 at 17:22
  • @RetiredNinja im using the command `mingw32-make -f MakeFile` to compile this. – Recondit Jun 15 '23 at 03:31

0 Answers0