<p>Looks like a typo since the compiler isn't complaining about the other SDL function calls. You probably need to change <code>SDL_setRenderDrawColor</code> to <code>SDL_SetRenderDrawColor</code></p>
<p><a href="https://wiki.libsdl.org/SDL2/SDL_SetRenderDrawColor" rel="nofollow noreferrer">https://wiki.libsdl.org/SDL2/SDL_SetRenderDrawColor</a></p>

CC BY-SA 4.0
2023-05-15T12:29:13.263Z
2023-05-15T12:29:13.263Z
Joshua Kennedy
<p>I am getting</p>
<p>C:\Users\rasmu\AppData\Local\Temp\ccwOn3mM.o:main.c:(.text+0x11f): undefined reference to `SDL_setRenderDrawColor'</p>
<p>C:\Users\rasmu\AppData\Local\Temp\ccwOn3mM.o:main.c:(.text+0x155): undefined reference to `SDL_setRenderDrawColor'</p>
<p>when i try to compile my basic SDL2 c program.
My code is</p>
<pre><code>#define ASSERT(_e, ...) if (!(_e)) { fprintf(stderr, __VA_ARGS__); exit(1); }
#include &lt;SDL.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdbool.h&gt;
#include &lt;stdint.h&gt;


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),
        &quot;SDL failed to init: %s\n&quot;,
        SDL_GetError()
    );
    state.window = 
        SDL_CreateWindow(
            &quot;Game&quot;,
            SDL_WINDOWPOS_CENTERED_DISPLAY(1),
            SDL_WINDOWPOS_CENTERED_DISPLAY(1),
            1280,
            720,
            SDL_WINDOW_ALLOW_HIGHDPI
        );
        
    ASSERT(state.window, &quot;failed to create SDL window: %s\n&quot;, 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(&amp;ev)){
            switch(ev.type){
                case SDL_QUIT:
                    state.quit = true;
                    break;
            }
        }
    }


        
    
    SDL_DestroyWindow(state.window);
    free(state.pixels);
    SDL_QUIT;
    return 0;
}
</code></pre>
<p>And my make file looks like this</p>
<pre><code>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 : <span class="math-container">$(OBJS)
$</span>(CC) <span class="math-container">$(OBJS) $</span>(INCLUDE_PATHS) <span class="math-container">$(LIBRARY_PATHS) $</span>(COMPILER_FLAGS) -o <span class="math-container">$(OBJ_NAME) $</span>(LINKER_FLAGS)
</code></pre>
<p>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.</p>

CC BY-SA 4.0
2023-03-08T07:39:52.990Z
'undefined reference' is always a linker error. Means the linker doesn't find the SDL library. Headers of libraries usually only tell the compiler what is available, not how it is implemented. So every time you use a function deklared in the header, the compiler "leaves a note for the linker to fill in the missing bits". If the compiler doesn't write such a "note", because you didn't use a function from the header, the linker has nothing to complain about. Long story short, check the make file. Further suggestion: use "cmake" in the future instead of "make"
wychmaster
<2d-graphics><pixel-graphics>
undefined reference to `SDL_setRenderDrawColor'
sumsar8
# undefined reference to `SDL_setRenderDrawColor'

(Asked by: username_0 on 2023-03-07)

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.

**Tags:** 2d-graphics, pixel-graphics

> **Comments:**
> **username_1**: 'undefined reference' is always a linker error. Means the linker doesn't find the SDL library. Headers of libraries usually only tell the compiler what is available, not how it is implemented. So every time you use a function deklared in the header, the compiler "leaves a note for the linker to fill in the missing bits". If the compiler doesn't write such a "note", because you didn't use a function from the header, the linker has nothing to complain about. Long story short, check the make file. Further suggestion: use "cmake" in the future instead of "make"  

---

## 1 answers

### Answer by username_2 on 2023-05-15. Score: 2

Looks like a typo since the compiler isn't complaining about the other SDL function calls. You probably need to change `SDL_setRenderDrawColor` to `SDL_SetRenderDrawColor`

<https://wiki.libsdl.org/SDL2/SDL_SetRenderDrawColor>


---

