SDL Problem

Hi,

I’m having trouble compiling an SDL problem. This is the problem I’m
trying to compile…

main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

}

When I run “gcc testsdl.c” I get the following output…

#include <stdlib.h>
#include <SDL.h>
[root at localhost redneon]# gcc testsdl.c
/tmp/ccN53jU1.o: In function main': /tmp/ccN53jU1.o(.text+0xc): undefined reference toSDL_Init’
/tmp/ccN53jU1.o(.text+0x20): undefined reference to SDL_GetError' /tmp/ccN53jU1.o(.text+0x4b): undefined reference toSDL_Quit’
collect2: ld returned 1 exit status
[root at localhost redneon]#

I also had troubles when installing SDL. I couldn’t get gcc to find <SDL.h> so I
ended up moving the files /usr/local/include/SDL/* to /usr/include so that it
recognised that the files were actually there.

Can anyone help?

Darrell

I’m having trouble compiling an SDL problem. This is the problem I’m
trying to compile…

When I run “gcc testsdl.c” I get the following output…

gcc needs to be told where the header files are, and to link the SDL
libraries. For the former, add the flag -I/usr/include/SDL (or whereever the
header files are) and for the latter, you’ll need -L/usr/lib to tell it to
get libraries from /usr/lib (modify to suit your system), -lSDL to link with
the main SDL library, -lpthread to link with the POSIX threads library, and
so on.

You might be wondering where I pulled these flags from. You don’t have to
remember them (and indeed, you shouldn’t – they’ll change from
installation to installation); when you install SDL you’ll also get a small
script called sdl-config that provides the neccessary flags. On my Debian
box running woody (the testing release), I get:

rapacity at fire:~$ sdl-config --cflags
-I/usr/include/SDL -D_REENTRANT
rapacity at fire:~$ sdl-config --libs
-L/usr/lib -lSDL -lpthread -L/usr/X11R6/lib -lXxf86dga -lXxf86vm -lXv

rapacity at fire:~$ gcc sdl-config --cflags testsdl.c sdl-config --libs

Produces a.out …

I also had troubles when installing SDL. I couldn’t get gcc to find
<SDL.h> so I ended up moving the files /usr/local/include/SDL/* to
/usr/include so that it recognised that the files were actually there.

Use the flags as provided by sdl-config --cflags to get the proper location
of the include files.

The preferrable way to do this is to use the GNU autoconf tools to
automatically produce Makefiles across various platforms. The easiest way to
do this is to grab the files from a working SDL app that uses them (some of
the demo programs, for example) and modifying them to fit your needs. They’re
not as scary as they first same, and you don’t really need to understand
them to be able to use them :-)On 7 Jan 2002, Darrell Blake wrote:


Mike.

Hi All,
I m using Dev c++ and have configured SDL properly on it. Now I m
making a car racing program in which the user will enter the speed of the
car and the car will run on that speed only. Joysticks will control the
movement of car. My query is that with SDL the output instead of appearing
on a console window, goes to a “stdout.txt” file. So far so good. But as i
mentioned I first need to take data from the user which will be the basis of
my program. When I try to get data from the user, it wont let me. I cant
enter any data on the console window because of presence of SDL libraries
and this generates “stderr.txt” empty file, instead of “stdout.txt” file. So
can you plz tell me how can i solve this problem? How can I get the data
from the user without disturbing SDL initialization and usage in the
program? Is there any solution or workaround to this? I would really
appreciate your help on this.

Regards:
Prathmesh

[…]

I cant enter
any data on the console window because of presence of SDL libraries
and this generates “stderr.txt” empty file, instead of "stdout.txt"
file.
[…]

You’re not supposed to mix SDL and stdio. The interaction between
consoles and the SDL window is highly platform dependent, and
sometimes flaky or even nonexistent. If you’re using a fullscreen
mode, there may be no way of switching to the desktop/console, so
your only option would be to trap a suitable key combination and
manually mess with the SDL display.

Build your input around SDL events and the SDL window. If you don’t
feel like implementing a text input widget or a quake style console,
there are a few GUI toolkits and consoles for SDL. Some of the font
libs also have a simple text input feature, which would probably be
the simplest and most lightweight solution. Have a look at the list
of libraries on the SDL site, or just google some.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Tuesday 28 October 2003 08.28, Prathmesh Mahidharia wrote: