Telmo Vaz
Telmo Vaz

Reputation: 57

Undefined reference to SDL_init?

I'm trying to compile this code:

#include "SDL/SDL.h"

int main(void) {

    SDL_Surface *Hello = NULL;
    SDL_Surface *Screen = NULL;

    SDL_Init( SDL_INIT_EVERYTHING );

    return 0;
}

But it happens that the compiler says that:

undefined reference to SDL_Init

I don't know why this is happening. I'm using Debian Mint and Code::Blocks. Could you help me?

Upvotes: -1

Views: 3808

Answers (2)

parkydr
parkydr

Reputation: 7784

It looks like you haven't got -lSDL on your link line.

sdl-config returns the compile and link flags for your installation of SDL.

Assuming the program is sdl.cpp

g++ -o sdl `sdl-config --cflags` sdl.cpp `sdl-config --libs`

Should give you the correct flags.

Upvotes: 2

user2615926
user2615926

Reputation:

Go to project and then build options and select your project name.

Now go to the linker setting and type the following lines in the Other Linker options textbox:

-lSDLmain
-lSDL

SDL also requires command line arguments in the main function so you should change

int main(void)

to

int main(int argc, char **argv)

Now compile your project and it should work.

Upvotes: 0

Related Questions