0
votes

I am beginning to use the SDL library for the first time and I used the apt-get install to download it onto the windows subsystem (Ubuntu). When I make calls to functions from the SDL library and then run the makefile, I am presented with:

/home/display.c:13: undefined reference to `SDL_Init'
/home/display.c:14: undefined reference to `SDL_GetError'
/home/display.c:17: undefined reference to `SDL_CreateWindow'
/home/display.c:19: undefined reference to `SDL_GetError'
/home/display.c:22: undefined reference to `SDL_CreateRenderer'
/home/display.c:24: undefined reference to `SDL_GetError'

The makefile looks like:

gcc -Wall -Werror -Wextra -Wunused -std=gnu99  -g -O0 -Wpedantic -lpthread -lSDL2main -lSDL2

I believe the issue is in linking and that the compiler cannot find where SDL is. However, if this were the case, there should be an error stating that #include SDL2/SDL.h cannot be found. Could this be an installation issue or an issue with the way I link SDL in the makefile?

1
When using a library you need to understand two separate steps in building a C program: compiling and linking. You will get errors about missing header files if the compiler can't find some. What you got is an error from the linker that cannot resolve the references to SDL_.... Perhaps it needs some help to find the library files, for example libSDL2.a. - the busybee

1 Answers

1
votes

The order in which I was placing the flags was incorrect. The libraries should be after the .c and .h files.