A problem about SDL

Hello,

     I am a fresh programmer, and want to study SDL nowadays, but now, I am in trouble with SDL.
     I installed all the libraries I known which can be seen below, but they didn't work.

     My OS is RedHat Linux.

     [root at RedHat share]# rpm -qa |grep SDL
     SDL-1.2.5-3
     SDL_net-1.2.4-5
     SDL-devel-1.2.5-3
     SDL_image-devel-1.2.2-5
     SDL_net-devel-1.2.4-5
     SDL_mixer-1.2.4-7
     SDL_image-1.2.2-5
     SDL_mixer-devel-1.2.4-7

     I have a simple program named test.cpp.

     #include "SDL/SDL.h"
 
     int main( int argc, char* argv[])
     {
      SDL_Init(SDL_INIT_EVERYTHING);
      SDL_Quit();
      return 0;
     }

     The following error is given when the program executed:

     [root at RedHat share]# g++ -o test test.cpp -ISDL
     /tmp/cck4qE54.o(.text+0x19): In function `main':
     : undefined reference to `SDL_Init'
     /tmp/cck4qE54.o(.text+0x21): In function `main':
     : undefined reference to `SDL_Quit'
     collect2: ld returned 1 exit status

     Now I am stuck.
     I am looking forward to hear from you. Thank you very much.

     yours sincerely,
     Young Boy

It’s bee years since I’ve done anything Unix/Linux related but I’ll take a stab from memory.

I think you’re doing an include for SDL. But shouldn’t there be something on the command line to tell it to link to the SDL library? A -L option while compiling?–
Lilith

On 6/23/2007 at 8:52 PM, wrote:

Hello,
I am a fresh programmer, and want to study SDL nowadays, but now, I am in trouble with SDL.
I installed all the libraries I known which can be seen below, but they didn’t work.
My OS is RedHat Linux.
[root at RedHat share]# rpm -qa |grep SDL
SDL-1.2.5-3
SDL_net-1.2.4-5
SDL-devel-1.2.5-3
SDL_image-devel-1.2.2-5
SDL_net-devel-1.2.4-5
SDL_mixer-1.2.4-7
SDL_image-1.2.2-5
SDL_mixer-devel-1.2.4-7
I have a simple program named test.cpp.
#include “SDL/SDL.h”

  int main( int argc, char* argv[]) 
 { 
  SDL_Init(SDL_INIT_EVERYTHING); 
  SDL_Quit(); 
  return 0; 
 } 
 The following error is given when the program executed: 
 [root at RedHat share]# g++ -o test test.cpp -ISDL 
 /tmp/cck4qE54.o(.text+0x19): In function `main': 
 : undefined reference to `SDL_Init' 
 /tmp/cck4qE54.o(.text+0x21): In function `main': 
 : undefined reference to `SDL_Quit' 
 collect2: ld returned 1 exit status 
 Now I am stuck. 
 I am looking forward to hear from you. Thank you very much. 

&nb sp; yours sincerely,
Young Boy

??? ( http://goto.mail.sohu.com/goto.php3?code=mailadt-ta1 )
*???>> ( http://goto.mail.sohu.com/goto.php3?code=mailadt-ta )

 [root at RedHat share]# g++ -o test test.cpp -ISDL

That “-ISDL” probably needs to be “-lSDL” (lowercase L, not uppercase i).

You might want to do this, though:

g++ -o test test.cpp `sdl-config --cflags --libs`

(note the “`” is not a “’”)

–ryan.

yangbocai2002 at sohu.com wrote:

[snip]
I have a simple program named test.cpp.

 #include "SDL/SDL.h"

 int main( int argc, char* argv[])
 {
  SDL_Init(SDL_INIT_EVERYTHING);
  SDL_Quit();
  return 0;
 }

Here’s a different opinion. For beginners, never write such
programs from scratch! :slight_smile: Try the test programs first. Then, try
simple programs, like Sam’s aliens demo. Then, invest some time in
learning how gcc is called and how to write simple Makefiles, or
learn autoconf. Once you’ve got that, you can start modifying and
learning source code of programs that work.

Find the test programs in the standard SDL library, and use the
standard way: configure, compile, test. If you can’t find the test
programs anywhere, grab the SDL sources and copy the test programs
from there.

HTH,–
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

Hi,

In Terminal:
tom at pegasus:~$ sdl-config --libs
-L/usr/lib -lSDL

tom at pegasus:~$ sdl-config --cflags
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT

So:

test: test.cpp
gcc -L/usr/lib -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -o\
test test.cpp

this works for me on my Ubuntu Feisty Box.-----------------------------------------------
Tom

yangbocai2002 at sohu.com schrieb:

Hello,

 I am a fresh programmer, and want to study SDL nowadays, but now, I

am in trouble with SDL.
I installed all the libraries I known which can be seen below, but
they didn’t work.

 My OS is RedHat Linux.

 [root at RedHat share]# rpm -qa |grep SDL
 SDL-1.2.5-3
 SDL_net-1.2.4-5
 SDL-devel-1.2.5-3
 SDL_image-devel-1.2.2-5
 SDL_net-devel-1.2.4-5
 SDL_mixer-1.2.4-7
 SDL_image-1.2.2-5
 SDL_mixer-devel-1.2.4-7

 I have a simple program named test.cpp.

 #include "SDL/SDL.h"

 int main( int argc, char* argv[])
 {
  SDL_Init(SDL_INIT_EVERYTHING);
  SDL_Quit();
  return 0;
 }

 The following error is given when the program executed:

 [root at RedHat share]# g++ -o test test.cpp -ISDL
 /tmp/cck4qE54.o(.text+0x19): In function `main':
 : undefined reference to `SDL_Init'
 /tmp/cck4qE54.o(.text+0x21): In function `main':
 : undefined reference to `SDL_Quit'
 collect2: ld returned 1 exit status

 Now I am stuck.
 I am looking forward to hear from you. Thank you very much.

 yours sincerely,
 Young Boy

???
http://goto.mail.sohu.com/goto.php3?code=mailadt-ta1
*???>>
http://goto.mail.sohu.com/goto.php3?code=mailadt-ta



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

try

#include <SDL/SDL.h>

instead of

#include “SDL/SDL.h”–
http://fog.neopages.org/

try

#include <SDL/SDL.h>

instead of

#include “SDL/SDL.h”

The most portable way is:
#include “SDL.h”

and then use sdl-config on Unix to set up the correct include path.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Hi, OTish, but:On Mon, 25 Jun 2007 08:03:32 -0700 Sam Lantinga wrote:

try

#include <SDL/SDL.h>

instead of

#include “SDL/SDL.h”

The most portable way is:
#include “SDL.h”

and then use sdl-config on Unix to set up the correct include path.

I remember reading this in the past, and following that advice. I then got
a really confusing error report from someone trying to compile the project
I’d used it in, about it not finding whatever include files in such-and-such
directory, and people complained that I should be using sdl-config to get
the paths and not hard coding them. But I HAD been using sdl-config, I
hadn’t hard-coded the paths at all. I was quite baffled.

Turns out, it was because I had bundled the up-to-date Makefile.dep file
my build process made, which was only reasonable, ordinary users shouldn’t
need to regenerate the dependancy info. But the standard process for doing
this considers headers included between ""s to be parts of your project,
compared to those between < > brackets, which it considers to be system
headers. So it was also putting all the SDL header’s paths (and their own
dependancies too? I forget, this was years ago) in the Makefile.dep, and
screwing things up for people who had SDL installed in different places
to me.

Obviously I could’ve removed the file before distributing, but it had never
occurred to me I might have to. Is this inclusion of SDL headers in
with the dependancy info actually desirable behaviour somehow? (it seems
wrong to me) If so, is that why #include “SDL.h” is considerd more portable,
or is it that maybe some compilers won’t accept non-standard paths being
included the other way?

Meanwhile I tend to just use #include <SDL.h> nowadays, and it doesn’t give
me problems, but maybe it would in some other circumstances, so I’m curious.

-Tom Barnes-Lawrence
(BTW, thanks to Kostas Kostiadis for replying to my earlier question, even
if he didn’t quite answer it- it was encouraging advice at least, and I
ended up just trying what seemed obvious and it worked easily!)

I think I need a new signature