I am getting
C:\Users\rasmu\AppData\Local\Temp\ccwOn3mM.o:main.c:(.text+0x11f): undefined reference to `SDL_setRenderDrawColor'
C:\Users\rasmu\AppData\Local\Temp\ccwOn3mM.o:main.c:(.text+0x155): undefined reference to `SDL_setRenderDrawColor'
when i try to compile my basic SDL2 c program. My code is
#define ASSERT(_e, ...) if (!(_e)) { fprintf(stderr, __VA_ARGS__); exit(1); }
#include <SDL.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
typedef float f32;
typedef double f64;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 720;
const int FPS = 30;
typedef struct {
SDL_Window* window;
SDL_Texture* texture;
SDL_Renderer* renderer;
u32* pixels;
bool quit;
} state;
u32* init_pixels();
void put_pixel(state state);
int main( int argc, char* args[]){
state state;
ASSERT(
!SDL_Init(SDL_INIT_VIDEO),
"SDL failed to init: %s\n",
SDL_GetError()
);
state.window =
SDL_CreateWindow(
"Game",
SDL_WINDOWPOS_CENTERED_DISPLAY(1),
SDL_WINDOWPOS_CENTERED_DISPLAY(1),
1280,
720,
SDL_WINDOW_ALLOW_HIGHDPI
);
ASSERT(state.window, "failed to create SDL window: %s\n", SDL_GetError());
state.pixels = malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 4);
state.renderer =
SDL_CreateRenderer(
state.window,
-1,
NULL
);
SDL_setRenderDrawColor(state.renderer,0,0,0,255);
SDL_RenderClear(state.renderer);
SDL_setRenderDrawColor(state.renderer,255,255,255,255);
SDL_RenderDrawPoint(state.renderer,SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
SDL_RenderPresent(state.renderer);
while(!state.quit){
SDL_Event ev;
while(SDL_PollEvent(&ev)){
switch(ev.type){
case SDL_QUIT:
state.quit = true;
break;
}
}
}
SDL_DestroyWindow(state.window);
free(state.pixels);
SDL_QUIT;
return 0;
}
And my make file looks like this
OBJS = main.c
CC = gcc
INCLUDE_PATHS = -IC:\mingw_dev_lib\include\SDL2
LIBRARY_PATHS = -LC:\mingw_dev_lib\lib
COMPILER_FLAGS = -w -Wl,-subsystem,windows
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2
OBJ_NAME = game
all : $(OBJS)
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) -o $(OBJ_NAME) $(LINKER_FLAGS)
I do believe it has something to do with the linking of the SDL2 library but it seems weird since the SDL.h works fine but only when I have tried to use the SDL_setRenderDrawColor() function. I am quite new to SDL and linking libraries.