SDL library in linux

2019-08-17 17:04发布

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 dont know why this is happening. I'm using Debian Mint and Code::Blocks. Could you Help me?

2条回答
Root(大扎)
2楼-- · 2019-08-17 17:54

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.

查看更多
太酷不给撩
3楼-- · 2019-08-17 17:56

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.

查看更多
登录 后发表回答