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
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 :)