-3

I'm using Kubuntu 18.04

So i recently tried to use SDL2, i wanted to create a simple window showing a few pictures following a tutorial but i was unable to compile the example code.

When i try to compile the code i get:

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_ceilf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_acosf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_floorf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_fabsf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_LoadFile_RW'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_fmodf'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.so: undefined reference to `SDL_atan2f'
collect2: error: ld returned 1 exit status

Command used:

gcc SDLProject.c -o SDLProject `sdl2-config --cflags --libs` -lSDL2_gfx -lSDL2_image

Command used to install SDL2 libs:

sudo apt install libsdl2-dev libsdl2-gfx-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev

Installed packages:

sudo apt list --installed | grep "sdl"

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libsdl2-2.0-0/bionic-updates,now 2.0.8+dfsg1-1ubuntu1.18.04.3 amd64 [installed]
libsdl2-dev/bionic-updates,now 2.0.8+dfsg1-1ubuntu1.18.04.3 amd64 [installed]
libsdl2-gfx-1.0-0/bionic,now 1.0.4+dfsg-1 amd64 [installed,automatic]
libsdl2-gfx-dev/bionic,now 1.0.4+dfsg-1 amd64 [installed]
libsdl2-image-2.0-0/bionic,now 2.0.3+dfsg1-1 amd64 [installed,automatic]
libsdl2-image-dev/bionic,now 2.0.3+dfsg1-1 amd64 [installed]
libsdl2-mixer-2.0-0/bionic,now 2.0.2+dfsg1-2 amd64 [installed,automatic]
libsdl2-mixer-dev/bionic,now 2.0.2+dfsg1-2 amd64 [installed]
libsdl2-ttf-2.0-0/bionic,now 2.0.14+dfsg1-2 amd64 [installed,automatic]
libsdl2-ttf-dev/bionic,now 2.0.14+dfsg1-2 amd64 [installed]

I already tried deleting everything that is related to SDL / SDL2 and only reinstalling the ones the project uses (SDL2, gfx and image) and i found out that this error only happens when i try to inlude the SDL_image.h and I'm able to run other exmaple codes that does not use it.

I do not think that the error is related to the code itself but:

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

typedef enum Babu {
    VKiraly, VVezer, VBastya, VFuto, VHuszar, VGyalog,
    SKiraly, SVezer, SSastya, SFuto, SHuszar, SGyalog
} Babu;

enum { MERET = 52 };


void babu_rajzol(SDL_Renderer *renderer, SDL_Texture *babuk, Babu melyik, int x, int y) {

    SDL_Rect src = { (melyik % 6) * 62 + 10, (melyik / 6) * 60 + 10, MERET, MERET };
    SDL_Rect dest = { x, y, MERET, MERET };
    SDL_RenderCopy(renderer, babuk, &src, &dest);
}


void sdl_init(int szeles, int magas, SDL_Window **pwindow, SDL_Renderer **prenderer) {
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        SDL_Log("Nem indithato az SDL: %s", SDL_GetError());
        exit(1);
    }
    SDL_Window *window = SDL_CreateWindow("SDL peldaprogram", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, szeles, magas, 0);
    if (window == NULL) {
        SDL_Log("Nem hozhato letre az ablak: %s", SDL_GetError());
        exit(1);
    }
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
    if (renderer == NULL) {
        SDL_Log("Nem hozhato letre a megjelenito: %s", SDL_GetError());
        exit(1);
    }
    SDL_RenderClear(renderer);

    *pwindow = window;
    *prenderer = renderer;
}


int main(int argc, char *argv[]) {
    SDL_Window *window;
    SDL_Renderer *renderer;
    sdl_init(320, 200, &window, &renderer);

    SDL_Texture *babuk = IMG_LoadTexture(renderer, "pieces.png");
    if (babuk == NULL) {
        SDL_Log("Nem nyithato meg a kepfajl: %s", IMG_GetError());
        exit(1);
    }

    boxRGBA(renderer, 0, 0, 319, 199, 0x90, 0xE0, 0x90, 0xFF);
    babu_rajzol(renderer, babuk, VKiraly, 82, 74);
    babu_rajzol(renderer, babuk, SGyalog, 82+MERET, 74);
    babu_rajzol(renderer, babuk, VHuszar, 82+2*MERET, 74);
    SDL_RenderPresent(renderer);

    SDL_DestroyTexture(babuk);

    SDL_Event event;
    while (SDL_WaitEvent(&event) && event.type != SDL_QUIT) {
    }

    SDL_Quit();
    return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Zhorer5231
  • 117
  • 2
  • 3
  • 14
  • 2
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ulrich Eckhardt May 04 '19 at 18:52
  • Please add to question outputs of `sdl2-config --cflags --libs`, `nm -D /usr/lib/x86_64-linux-gnu/libSDL2.so | grep SDL_ceilf` and probably `locate libSDL2.so` if you have locate and not-very-outdated file database. These functions were added in SDL 2.0.8 which you appear to be using - but do you really, or there is other `libSDL2.so` in your filesystem that takes precedence? – keltar May 05 '19 at 05:18

1 Answers1

1

You did not get the sdl package which contains sdl-config. You can get it from

sudo apt install libsdl1.2-dev
bitbangs
  • 506
  • 3
  • 6
  • Yep, that solved the issue, i guess the tutorial i was following forgot the mention that i needed the older version as well if i wanted to use the sdl-config. – Zhorer5231 May 05 '19 at 20:18