简体   繁体   English

如何在 Linux 中使用 SDL?

[英]how to use SDL in linux?

The linux server at my school is just a bare-bone server, no x-windows, just a command line interface.我学校的 linux 服务器只是一个准系统服务器,没有 x-windows,只是一个命令行界面。

I tried to make a graphical c program on that server but found much difficulties.我试图在那台服务器上制作一个图形化的 c 程序,但发现很多困难。 I use SDL library but every time I try to compile my code with gcc, I get:我使用 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'
...

Does anybody knows how to fix the problem?有谁知道如何解决这个问题? If not, is there anybody who has done graphic program in c in linux, please help!如果没有,有没有人在linux下用c做过图形程序,请帮忙! I would appreciate.我将不胜感激。 Thanks.谢谢。

The recommended way of linking SDL on linux is using the sdl-config script.在 linux 上链接 SDL 的推荐方法是使用sdl-config脚本。

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.其中 ` 是反勾号字符。

Add -lSDL to your compile line.-lSDL添加到您的编译行。

This tells gcc to link your code to the SDL library.这告诉gcc将您的代码链接到 SDL 库。

You're not linking to the SDL library.您没有链接到 SDL 库。 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.假设您使用的是 Linux 发行版附带的 SDL。 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. -I 和 -L 选项分别告诉 gcc 在哪里查找包含文件和库。 The first command doesn't need them because if you use the stock SDL for your system, they're in the default locations.第一个命令不需要它们,因为如果您为系统使用库存 SDL,它们位于默认位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM