# A problem about SDL

**URL:** <https://discourse.libsdl.org/t/a-problem-about-sdl/14631>\
**Category:** SDL Development\
**Created:** [June 24, 2007, 1:52am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631 "2007-06-24T01:52:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yangbocai2002\_at\_soh](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yangbocai2002\_at\_soh](https://discourse.libsdl.org/u/yangbocai2002_at_soh)\
**Post date:** [June 24, 2007, 1:52am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/1 "2007-06-24T01:52:09Z")

</div>

Hello,

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

&nbsp;&nbsp;&nbsp;&nbsp; My OS is RedHat Linux.

&nbsp;&nbsp;&nbsp;&nbsp; [root at RedHat share]# rpm -qa |grep SDL   
&nbsp;&nbsp;&nbsp;&nbsp; SDL-1.2.5-3   
&nbsp;&nbsp;&nbsp;&nbsp; SDL\_net-1.2.4-5   
&nbsp;&nbsp;&nbsp;&nbsp; SDL-devel-1.2.5-3   
&nbsp;&nbsp;&nbsp;&nbsp; SDL\_image-devel-1.2.2-5   
&nbsp;&nbsp;&nbsp;&nbsp; SDL\_net-devel-1.2.4-5   
&nbsp;&nbsp;&nbsp;&nbsp; SDL\_mixer-1.2.4-7   
&nbsp;&nbsp;&nbsp;&nbsp; SDL\_image-1.2.2-5   
&nbsp;&nbsp;&nbsp;&nbsp; SDL\_mixer-devel-1.2.4-7

&nbsp;&nbsp;&nbsp;&nbsp; I have a simple program named test.cpp.

&nbsp;&nbsp;&nbsp;&nbsp; #include "SDL/SDL.h"   
&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp; int main( int argc, char\* argv[])   
&nbsp;&nbsp;&nbsp;&nbsp; {   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SDL\_Init(SDL\_INIT\_EVERYTHING);   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SDL\_Quit();   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;   
&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The following&nbsp;error is given when the program executed:

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

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

&nbsp;&nbsp;&nbsp;&nbsp; yours sincerely,   
&nbsp;&nbsp;&nbsp;&nbsp; Young Boy

---

<div class="post-metadata">

**Author:** ![Lilith\_Calbridge](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/c57346/32.png) [@Lilith\_Calbridge](https://discourse.libsdl.org/u/Lilith_Calbridge)\
**Post date:** [June 24, 2007, 3:19am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/2 "2007-06-24T03:19:10Z")

</div>

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-ta1) )  
\*???\>\> ( [http://goto.mail.sohu.com/goto.php3?code=mailadt-ta](http://goto.mail.sohu.com/goto.php3?code=mailadt-ta) )

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [June 24, 2007, 3:21am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/3 "2007-06-24T03:21:24Z")

</div>

> ```
> [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.

---

<div class="post-metadata">

**Author:** ![Kein-Hong\_Man](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@Kein-Hong\_Man](https://discourse.libsdl.org/u/Kein-Hong_Man)\
**Post date:** [June 24, 2007, 6:03am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/4 "2007-06-24T06:03:26Z")

</div>

yangbocai2002 at [sohu.com](http://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! 🙂 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

---

<div class="post-metadata">

**Author:** ![Thomas\_Schmid](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@Thomas\_Schmid](https://discourse.libsdl.org/u/Thomas_Schmid)\
**Post date:** [June 24, 2007, 6:27am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/5 "2007-06-24T06:27:44Z")

</div>

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](http://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-ta1)  
> \*???\>\>  
> [http://goto.mail.sohu.com/goto.php3?code=mailadt-ta](http://goto.mail.sohu.com/goto.php3?code=mailadt-ta)
> 
> * * *
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Danilo\_Vargas](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Danilo\_Vargas](https://discourse.libsdl.org/u/Danilo_Vargas)\
**Post date:** [June 25, 2007, 11:30am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/6 "2007-06-25T11:30:18Z")

</div>

try

#include \<SDL/SDL.h\>

instead of

#include “SDL/SDL.h”–  
[http://fog.neopages.org/](http://fog.neopages.org/)

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [June 25, 2007, 3:03pm UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/7 "2007-06-25T15:03:32Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Tom\_Barnes-Lawrence](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@Tom\_Barnes-Lawrence](https://discourse.libsdl.org/u/Tom_Barnes-Lawrence)\
**Post date:** [June 26, 2007, 6:35am UTC](https://discourse.libsdl.org/t/a-problem-about-sdl/14631/8 "2007-06-26T06:35:07Z")

</div>

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
