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.
Add
-lSDL
to your compile line.This tells
gcc
to link your code to the SDL library.The recommended way of linking SDL on linux is using the sdl-config script.
example:
or example:
where ` is the back tick character.
You're not linking to the SDL library. Your command should look something like this:
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:
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.