Why am I getting a compile error?

#include <SDL2/SDL.h>

struct box_data
    SDL_FRect bounds;
    SDL_Color fill_color;

SDL_Window *window;
SDL_Event event;
SDL_Renderer *renderer;

box_data bot;

int main()
    window = SDL_CreateWindow("musor", SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, 800,
                              800, SDL_WINDOW_OPENGL);

    bot.bounds.w = 100;
    bot.bounds.h = 100;
    bot.fill_color = {255};

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

    while (window != NULL)
        while (SDL_PollEvent(&event))
            if (event.type == SDL_QUIT)
                window = NULL;

        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
        SDL_SetRenderDrawColor(renderer, bot.fill_color.r,
        SDL_RenderFillRectF(renderer, &bot.bounds);

Compilation command:
g++ main.cpp -o main -lSDL2

Compilation error:

/usr/bin/ld: /tmp/ccpdrdEM.o: in function `main':
main.cpp:(.text+0x141): undefined reference to `SDL_RenderFillRectF'

Help me!

I think floating versions of SDL_Rect are undocumented and can’t be used currently so lose the F.

They are not part of the SDL 2.0.12. Although they were committed in 2018. See here.

So you’re probably using the wrong version of SDL2

The floating point versions absolutely are part of SDL 2.0.12 and part of the public API (the documentation on the SDL website is, unfortunately, out of date). In fact, internally the integer versions just call the floating point versions.

@RedBull4 is probably linking against an old SDL version. Check with

SDL_version compiled, linked;

printf("Compiled with SDL %d.%d.%d\n", compiled.major, compiled.minor, compiled.patch);
printf("Linked with SDL %d.%d.%d\n", linked.major, linked.minor, linked.patch);

If this doesn’t say SDL 2.0.12 for compiled, then you need to update to SDL 2.0.12.

Also, OP, compile with
g++ main.cpp -o main `sdl2-config --cflags --libs`

1 Like