如何在linux中使用SDL?

1 c graphics sdl

我学校的linux服务器只是一个裸机服务器,没有x-windows,只是一个命令行界面.

我试图在该服务器上制作图形化的c程序,但发现了很多困难.我使用SDL库但每次尝试使用gcc编译代码时,我得到:

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'
...
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决这个问题吗?如果没有,有没有人在linux中用c做过图形程序,请帮忙!我将不胜感激.谢谢.

nur*_*tin 11

在linux上链接SDL 的推荐方法是使用sdl-config脚本.

例:

gcc -c test.c $(sdl-config --cflags)
gcc -o test test.o $(sdl-config --libs)
./test
Run Code Online (Sandbox Code Playgroud)

或者示例:

gcc -o test test.c $(sdl-config --cflags --libs)
Run Code Online (Sandbox Code Playgroud)

其中`是后退刻度字符.


caf*_*caf 6

添加-lSDL到您的编译行.

这告诉gcc您将代码链接到SDL库.