SDL library in linux

亡梦爱人 提交于 2019-12-13 04:42:21

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17846268/sdl-library-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!