how to use SDL in linux?

佐手、 提交于 2019-12-08 03:12:09

问题


The linux server at my school is just a bare-bone server, no x-windows, just a command line interface.

I tried to make a graphical c program on that server but found much difficulties. I use SDL library but every time I try to compile my code with gcc, I get:

testcursor.c:(.text+0x1ad): undefined reference to `SDL_Init'
testcursor.c:(.text+0x1b6): undefined reference to `SDL_GetError'
testcursor.c:(.text+0x200): undefined reference to `SDL_SetVideoMode'
...

Does anybody knows how to fix the problem? If not, is there anybody who has done graphic program in c in linux, please help! I would appreciate. Thanks.


回答1:


The recommended way of linking SDL on linux is using the sdl-config script.

example:

gcc -c test.c $(sdl-config --cflags)
gcc -o test test.o $(sdl-config --libs)
./test

or example:

gcc -o test test.c $(sdl-config --cflags --libs)

where ` is the back tick character.




回答2:


Add -lSDL to your compile line.

This tells gcc to link your code to the SDL library.




回答3:


You're not linking to the SDL library. Your command should look something like this:

gcc testcursor.c -lsdl

That's assuming you're using the SDL that came with your Linux distro. If you downloaded it and built it by hand, you might need something more complicated, like this:

gcc -I/usr/local/include/sdl testcursor.c -L/usr/local/lib -lsdl

The -I and -L options tell gcc where to look for include files and libraries, respectively. The first command doesn't need them because if you use the stock SDL for your system, they're in the default locations.



来源:https://stackoverflow.com/questions/1837639/how-to-use-sdl-in-linux

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