# Getting started with SDL in C

**URL:** <https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048>\
**Category:** SDL Development\
**Created:** [October 14, 2013, 5:36pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048 "2013-10-14T17:36:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 14, 2013, 5:36pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/1 "2013-10-14T17:36:20Z")

</div>

I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:

#include \<stdlib.h\>  
#include \<stdio.h\>  
#include “SDL.h”

int main(void)  
{  
? if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
? ? fprintf(stderr, “\nUnable to initialize SDL: ?%s\n”, SDL\_GetError());  
? ? return 1;  
? }  
? atexit(SDL\_Quit);

? return 0;  
}

When I try to compile my script (gcc example.c) I get an error:

example.c:3:17: error: SDL.h: No such file or directory  
example.c: In function ?main?:  
example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
example.c:7: error: (Each undeclared identifier is reported only once  
example.c:7: error: for each function it appears in.)  
example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)

I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.

What do I need to do to compile this program?

Thanks!

–Andrew

---

<div class="post-metadata">

**Author:** ![Jonas\_Kulla](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@Jonas\_Kulla](https://discourse.libsdl.org/u/Jonas_Kulla)\
**Post date:** [October 14, 2013, 5:47pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/2 "2013-10-14T17:47:10Z")

</div>

2013/10/14 Andrew Havens

> I’m getting started with SDL and C programming. I have experience with  
> other programming languages, but linking/compiling libraries in C is new to  
> me. I am using Mac 10.8 and have installed stable 2.0.0 using the  
> instructions in the read me (./configure; make; make install). Here is the  
> sample code that I am trying to compile:
> 
> #include \<stdlib.h\>  
> #include \<stdio.h\>  
> #include “SDL.h”
> 
> int main(void)  
> {  
> if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
> fprintf(stderr, “\nUnable to initialize SDL: %s\n”, SDL\_GetError());  
> return 1;  
> }  
> atexit(SDL\_Quit);
> 
> return 0;  
> }
> 
> When I try to compile my script (gcc example.c) I get an error:
> 
> example.c:3:17: error: SDL.h: No such file or directory  
> example.c: In function ?main?:  
> example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this  
> function)  
> example.c:7: error: (Each undeclared identifier is reported only once  
> example.c:7: error: for each function it appears in.)  
> example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this  
> function)  
> example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3  
> has type ?int?  
> example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3  
> has type ?int?  
> example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)
> 
> I tried searching the wiki, and tutorials, and any kind of documentation  
> that I could find, but I could not find any example anywhere that showed  
> how to properly compile a C program that uses SDL. Maybe this is common  
> knowledge and I should already know how to do this, but I don’t so I need  
> some help. Adding this type of information to the documentation would help  
> people like me in the future.
> 
> What do I need to do to compile this program?
> 
> Thanks!
> 
> –Andrew

Hi,

looks like you haven’t provided the correct include paths to gcc, so it  
can’t find the SDL header. You should definitely provide the command line  
you used trying to compile your sample.

Jonas

---

<div class="post-metadata">

**Author:** ![Aggelos\_Kolaitis](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@Aggelos\_Kolaitis](https://discourse.libsdl.org/u/Aggelos_Kolaitis)\
**Post date:** [October 14, 2013, 5:57pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/3 "2013-10-14T17:57:54Z")

</div>

In other words, you also have to link to the SDL2 libraries, since gcc does not do that on its own (for apparent reasons).

Practically, you should compile your application like this:

% gcc source.c -o program -lSDL2 -I/path/to/SDL2/headers

Or, if you have pkg-config:

% gcc source.c -o program $(pkg-config --libs --cflags sdl2)Sent from my iPod

On 14 ??? 2013, at 8:47 ?.?., Jonas Kulla wrote:

> 2013/10/14 Andrew Havens   
> I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:
> 
> #include \<stdlib.h\>  
> #include \<stdio.h\>  
> #include “SDL.h”
> 
> int main(void)  
> {  
> if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
> fprintf(stderr, “\nUnable to initialize SDL: %s\n”, SDL\_GetError());  
> return 1;  
> }  
> atexit(SDL\_Quit);
> 
> return 0;  
> }
> 
> When I try to compile my script (gcc example.c) I get an error:
> 
> example.c:3:17: error: SDL.h: No such file or directory  
> example.c: In function ?main?:  
> example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
> example.c:7: error: (Each undeclared identifier is reported only once  
> example.c:7: error: for each function it appears in.)  
> example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
> example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
> example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
> example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)
> 
> I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.
> 
> What do I need to do to compile this program?
> 
> Thanks!
> 
> –Andrew
> 
> Hi,
> 
> looks like you haven’t provided the correct include paths to gcc, so it  
> can’t find the SDL header. You should definitely provide the command line  
> you used trying to compile your sample.
> 
> Jonas
> 
> * * *
> 
> 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:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 14, 2013, 6:18pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/4 "2013-10-14T18:18:11Z")

</div>

Thanks! I think I just realized what pkg-config is for! That will be helpful to use in the future.

I just ran this and it worked:

gcc -o build/program example.c $(pkg-config --cflags --libs sdl2)

However, I tried to move the same thing to a Makefile, and it ignored all of the pkg-config stuff. Is there a different way to specify it in a Makefile? Or do you need to list out the response from?$(pkg-config --cflags --libs sdl2)?

–AndrewOn October 14, 2013 at 10:58:01 AM, neoaggelos at [gmail.com](http://gmail.com) (neoaggelos at [gmail.com](http://gmail.com)) wrote:

In other words, you also have to link to the SDL2 libraries, since gcc does not do that on its own (for apparent reasons).

Practically, you should compile your application like this:

% gcc source.c -o program -lSDL2 -I/path/to/SDL2/headers

Or, if you have pkg-config:

% gcc source.c -o program $(pkg-config --libs --cflags sdl2)

Sent from my iPod

On 14 ??? 2013, at 8:47 ?.?., Jonas Kulla wrote:

2013/10/14 Andrew Havens \<@Andrew\_Havens\>  
I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:

#include \<stdlib.h\>  
#include \<stdio.h\>  
#include “SDL.h”

int main(void)  
{  
? if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
? ? fprintf(stderr, “\nUnable to initialize SDL: ?%s\n”, SDL\_GetError());  
? ? return 1;  
? }  
? atexit(SDL\_Quit);

? return 0;  
}

When I try to compile my script (gcc example.c) I get an error:

example.c:3:17: error: SDL.h: No such file or directory  
example.c: In function ?main?:  
example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
example.c:7: error: (Each undeclared identifier is reported only once  
example.c:7: error: for each function it appears in.)  
example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)

I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.

What do I need to do to compile this program?

Thanks!

–Andrew

Hi,

looks like you haven’t provided the correct include paths to gcc, so it  
can’t find the SDL header. You should definitely provide the command line  
you used trying to compile your sample.

Jonas?

* * *

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)

* * *

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:** ![Jorgen\_Tjerno](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jorgen_tjerno/32/2088_2.png) [@Jorgen\_Tjerno](https://discourse.libsdl.org/u/Jorgen_Tjerno)\
**Post date:** [October 14, 2013, 10:27pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/5 "2013-10-14T22:27:23Z")

</div>

The syntax in Makefiles are different - how are you doing it in your Makefile?

You probably want $(shell pkg-config --cflags --libs sdl2) instead.

- J?rgen.\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
From: [sdl-bounces@lists.libsdl.org](mailto:sdl-bounces@lists.libsdl.org) [sdl-bounces at [lists.libsdl.org](http://lists.libsdl.org)] on behalf of Andrew Havens [andrewh at [copio.us](http://copio.us)]  
Sent: Monday, October 14, 2013 11:18 AM  
To: SDL Development List; neoaggelos at [gmail.com](http://gmail.com)  
Subject: Re: [SDL] Getting started with SDL in C

Thanks! I think I just realized what pkg-config is for! That will be helpful to use in the future.

I just ran this and it worked:

gcc -o build/program example.c $(pkg-config --cflags --libs sdl2)

However, I tried to move the same thing to a Makefile, and it ignored all of the pkg-config stuff. Is there a different way to specify it in a Makefile? Or do you need to list out the response from $(pkg-config --cflags --libs sdl2)?

–Andrew

On October 14, 2013 at 10:58:01 AM, neoaggelos at [gmail.com](http://gmail.com) (neoaggelos at [gmail.com](http://gmail.com)\<mailto://neoaggelos at [gmail.com](http://gmail.com)\>) wrote:

In other words, you also have to link to the SDL2 libraries, since gcc does not do that on its own (for apparent reasons).

Practically, you should compile your application like this:

% gcc source.c -o program -lSDL2 -I/path/to/SDL2/headers

Or, if you have pkg-config:

% gcc source.c -o program $(pkg-config --libs --cflags sdl2)

Sent from my iPod

On 14 ??? 2013, at 8:47 ?.?., Jonas Kulla \<nyocurio at [gmail.com](http://gmail.com)\<mailto:nyocurio at [gmail.com](http://gmail.com)\>\> wrote:

2013/10/14 Andrew Havens \<andrewh at [copio.us](http://copio.us)\<mailto:andrewh at [copio.us](http://copio.us)\>\>  
I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:

#include \<stdlib.h\>  
#include \<stdio.h\>  
#include “SDL.h”

int main(void)  
{  
if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
fprintf(stderr, “\nUnable to initialize SDL: %s\n”, SDL\_GetError());  
return 1;  
}  
atexit(SDL\_Quit);

return 0;  
}

When I try to compile my script (gcc example.c) I get an error:

example.c:3:17: error: SDL.h: No such file or directory  
example.c: In function ?main?:  
example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
example.c:7: error: (Each undeclared identifier is reported only once  
example.c:7: error: for each function it appears in.)  
example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)

I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.

What do I need to do to compile this program?

Thanks!

–Andrew

Hi,

looks like you haven’t provided the correct include paths to gcc, so it  
can’t find the SDL header. You should definitely provide the command line  
you used trying to compile your sample.

Jonas

* * *

SDL mailing list  
SDL at [lists.libsdl.org](http://lists.libsdl.org)\<mailto: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)

* * *

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:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 14, 2013, 10:34pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/6 "2013-10-14T22:34:07Z")

</div>

Yep, that worked. Thanks!

–AndrewOn October 14, 2013 at 3:27:29 PM, Jorgen Tjerno (jorgen at [valvesoftware.com](http://valvesoftware.com)) wrote:

The syntax in Makefiles are different - how are you doing it in your Makefile?

You probably want $(shell pkg-config --cflags --libs sdl2) instead.

- J?rgen.

From: [sdl-bounces@lists.libsdl.org](mailto:sdl-bounces@lists.libsdl.org) [sdl-bounces at [lists.libsdl.org](http://lists.libsdl.org)] on behalf of Andrew Havens [@Andrew_Havens]  
Sent: Monday, October 14, 2013 11:18 AM  
To: SDL Development List; neoaggelos at [gmail.com](http://gmail.com)  
Subject: Re: [SDL] Getting started with SDL in C

Thanks! I think I just realized what pkg-config is for! That will be helpful to use in the future.

I just ran this and it worked:

gcc -o build/program example.c $(pkg-config --cflags --libs sdl2)

However, I tried to move the same thing to a Makefile, and it ignored all of the pkg-config stuff. Is there a different way to specify it in a Makefile? Or do you need to list out the response from?$(pkg-config --cflags --libs sdl2)?

–Andrew  
On October 14, 2013 at 10:58:01 AM, neoaggelos at [gmail.com](http://gmail.com) (neoaggelos at [gmail.com](http://gmail.com)) wrote:

In other words, you also have to link to the SDL2 libraries, since gcc does not do that on its own (for apparent reasons).

Practically, you should compile your application like this:

% gcc source.c -o program -lSDL2 -I/path/to/SDL2/headers

Or, if you have pkg-config:

% gcc source.c -o program $(pkg-config --libs --cflags sdl2)

Sent from my iPod

On 14 ??? 2013, at 8:47 ?.?., Jonas Kulla wrote:

2013/10/14 Andrew Havens \<@Andrew\_Havens\>  
I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:

#include \<stdlib.h\>  
#include \<stdio.h\>  
#include “SDL.h”

int main(void)  
{  
? if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
? ? fprintf(stderr, “\nUnable to initialize SDL: ?%s\n”, SDL\_GetError());  
? ? return 1;  
? }  
? atexit(SDL\_Quit);

? return 0;  
}

When I try to compile my script (gcc example.c) I get an error:

example.c:3:17: error: SDL.h: No such file or directory  
example.c: In function ?main?:  
example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
example.c:7: error: (Each undeclared identifier is reported only once  
example.c:7: error: for each function it appears in.)  
example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)

I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.

What do I need to do to compile this program?

Thanks!

–Andrew

Hi,

looks like you haven’t provided the correct include paths to gcc, so it  
can’t find the SDL header. You should definitely provide the command line  
you used trying to compile your sample.

Jonas?

* * *

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)

* * *

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)

* * *

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:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 14, 2013, 5:58pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/7 "2013-10-14T17:58:28Z")

</div>

I already did. The only thing I used was:

gcc example.c

I’m not sure which files/directories/libraries or whatever to link to or include.

## Andrew Havens // Sr. Software Engineer //?COPIOUS @copiousagency---------------------------------------- (503) 780-6294?Phone 411 SW 6th Ave, Portland, OR 97204

[www.copio.us](http://www.copio.us)

On October 14, 2013 at 10:47:13 AM, Jonas Kulla (nyocurio at [gmail.com](http://gmail.com)) wrote:

2013/10/14 Andrew Havens \<@Andrew\_Havens\>  
I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:

#include \<stdlib.h\>  
#include \<stdio.h\>  
#include “SDL.h”

int main(void)  
{  
? if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
? ? fprintf(stderr, “\nUnable to initialize SDL: ?%s\n”, SDL\_GetError());  
? ? return 1;  
? }  
? atexit(SDL\_Quit);

? return 0;  
}

When I try to compile my script (gcc example.c) I get an error:

example.c:3:17: error: SDL.h: No such file or directory  
example.c: In function ?main?:  
example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
example.c:7: error: (Each undeclared identifier is reported only once  
example.c:7: error: for each function it appears in.)  
example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)

I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.

What do I need to do to compile this program?

Thanks!

–Andrew

Hi,

looks like you haven’t provided the correct include paths to gcc, so it  
can’t find the SDL header. You should definitely provide the command line  
you used trying to compile your sample.

Jonas?

* * *

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:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 14, 2013, 10:33pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/8 "2013-10-14T22:33:31Z")

</div>

Yep, that worked. Thanks!

–AndrewOn October 14, 2013 at 3:27:29 PM, Jorgen Tjerno (jorgen at [valvesoftware.com](http://valvesoftware.com)) wrote:

The syntax in Makefiles are different - how are you doing it in your Makefile?

You probably want $(shell pkg-config --cflags --libs sdl2) instead.

- J?rgen.

From: [sdl-bounces@lists.libsdl.org](mailto:sdl-bounces@lists.libsdl.org) [sdl-bounces at [lists.libsdl.org](http://lists.libsdl.org)] on behalf of Andrew Havens [@Andrew_Havens]  
Sent: Monday, October 14, 2013 11:18 AM  
To: SDL Development List; neoaggelos at [gmail.com](http://gmail.com)  
Subject: Re: [SDL] Getting started with SDL in C

Thanks! I think I just realized what pkg-config is for! That will be helpful to use in the future.

I just ran this and it worked:

gcc -o build/program example.c $(pkg-config --cflags --libs sdl2)

However, I tried to move the same thing to a Makefile, and it ignored all of the pkg-config stuff. Is there a different way to specify it in a Makefile? Or do you need to list out the response from?$(pkg-config --cflags --libs sdl2)?

–Andrew  
On October 14, 2013 at 10:58:01 AM, neoaggelos at [gmail.com](http://gmail.com) (neoaggelos at [gmail.com](http://gmail.com)) wrote:

In other words, you also have to link to the SDL2 libraries, since gcc does not do that on its own (for apparent reasons).

Practically, you should compile your application like this:

% gcc source.c -o program -lSDL2 -I/path/to/SDL2/headers

Or, if you have pkg-config:

% gcc source.c -o program $(pkg-config --libs --cflags sdl2)

Sent from my iPod

On 14 ??? 2013, at 8:47 ?.?., Jonas Kulla wrote:

2013/10/14 Andrew Havens \<@Andrew\_Havens\>  
I’m getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed stable 2.0.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:

#include \<stdlib.h\>  
#include \<stdio.h\>  
#include “SDL.h”

int main(void)  
{  
? if (SDL\_Init(SDL\_INIT\_VIDEO|SDL\_INIT\_TIMER) != 0) {  
? ? fprintf(stderr, “\nUnable to initialize SDL: ?%s\n”, SDL\_GetError());  
? ? return 1;  
? }  
? atexit(SDL\_Quit);

? return 0;  
}

When I try to compile my script (gcc example.c) I get an error:

example.c:3:17: error: SDL.h: No such file or directory  
example.c: In function ?main?:  
example.c:7: error: ?SDL\_INIT\_VIDEO? undeclared (first use in this function)  
example.c:7: error: (Each undeclared identifier is reported only once  
example.c:7: error: for each function it appears in.)  
example.c:7: error: ?SDL\_INIT\_TIMER? undeclared (first use in this function)  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:8: warning: format ?%s? expects type ?char \*?, but argument 3 has type ?int?  
example.c:11: error: ?SDL\_Quit? undeclared (first use in this function)

I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL. Maybe this is common knowledge and I should already know how to do this, but I don’t so I need some help. Adding this type of information to the documentation would help people like me in the future.

What do I need to do to compile this program?

Thanks!

–Andrew

Hi,

looks like you haven’t provided the correct include paths to gcc, so it  
can’t find the SDL header. You should definitely provide the command line  
you used trying to compile your sample.

Jonas?

* * *

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)

* * *

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)

* * *

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:** ![T\_Joseph\_Carter](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/t_joseph_carter/32/2525_2.png) [@T\_Joseph\_Carter](https://discourse.libsdl.org/u/T_Joseph_Carter)\
**Post date:** [October 16, 2013, 2:29am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/9 "2013-10-16T02:29:09Z")

</div>

A good start for SDL 2.0 would be to look at sdl2-config (or the  
equivalent pkg-config if you’re using that?)

The --cflags and --libs args are probably going to help a lot.

Simple incantation:

gcc -o example example.c `sdl2-config --cflags --libs`

If you’re going to write more complex code (and you will), you’ll  
need a build system. I suggest eschewing the traditional make(1) in  
favor of cmake. You could also set up XCode for SDL development, but  
I can’t really help with that. I have a hate/hate relationship with  
XCode. 😉

JosephOn Mon, Oct 14, 2013 at 10:58:28AM -0700, Andrew Havens wrote:

> I already did. The only thing I used was:
> 
> gcc example.c
> 
> I’m not sure which files/directories/libraries or whatever to link to or include.

---

<div class="post-metadata">

**Author:** ![Jared\_Maddox](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@Jared\_Maddox](https://discourse.libsdl.org/u/Jared_Maddox)\
**Post date:** [October 16, 2013, 4:42am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/10 "2013-10-16T04:42:41Z")

</div>

Sorry about that, accidentally hit the wrong keys.\> Date: Mon, 14 Oct 2013 10:58:28 -0700

> From: Andrew Havens   
> To: SDL Development List , Jonas Kulla  
>   
> Subject: Re: [SDL] Getting started with SDL in C  
> Message-ID: \<etPan.525c30c4.71f32454.438 at Andrews-MacBook-Air.local\>  
> Content-Type: text/plain; charset=“utf-8”
> 
> I already did. The only thing I used was:
> 
> gcc example.c
> 
> I’m not sure which files/directories/libraries or whatever to link to or  
> include.
> 
> Andrew Havens // Sr. Software Engineer //?COPIOUS  
> @copiousagency

Take a look inside your SDL (or SDL2) install directory. You should  
see a file somewhere in that hierarchy called sdl-config (or  
sdl2-config, or something else of the sort). Run that, and it should  
spit out a list of the compiler commands (including libraries, library  
locations, etc.) that you need to add in with everything else when  
doing the final compile.

---

<div class="post-metadata">

**Author:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 16, 2013, 5:03am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/11 "2013-10-16T05:03:58Z")

</div>

Yeah, I’m not interested in using XCode either. I’d rather not depend on an IDE. I’ve got a Makefile for automating the compile task. I’ve seen other projects use cmake, but I’m not familiar with what makes it different/better than make.

The pkg-config and sdl-config look awfully similar?what’s the difference? Why would I want to use sdl-config instead?

–Andrew

A good start for SDL 2.0 would be to look at sdl2-config (or the  
equivalent pkg-config if you’re using that?)

The --cflags and --libs args are probably going to help a lot.

Simple incantation:

gcc -o example example.c `sdl2-config --cflags --libs`

If you’re going to write more complex code (and you will), you’ll  
need a build system. I suggest eschewing the traditional make(1) in  
favor of cmake. You could also set up XCode for SDL development, but  
I can’t really help with that. I have a hate/hate relationship with  
XCode. 😉

JosephOn October 15, 2013 at 7:29:14 PM, T. Joseph Carter (tjcarter at [spiritsubstance.com](http://spiritsubstance.com)) wrote:

On Mon, Oct 14, 2013 at 10:58:28AM -0700, Andrew Havens wrote:

> I already did. The only thing I used was:
> 
> gcc example.c
> 
> I’m not sure which files/directories/libraries or whatever to link to or include.

* * *

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:** ![Aggelos\_Kolaitis](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@Aggelos\_Kolaitis](https://discourse.libsdl.org/u/Aggelos_Kolaitis)\
**Post date:** [October 16, 2013, 11:18am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/12 "2013-10-16T11:18:25Z")

</div>

Actually, ‘sdl2-config …’ is the same (at least for now) as ‘pkg-config sdl2 …’.

Assuming a proper SDL2 installation, you may use any of the two - I prefer pkg-config.

As for the traits of cmake (or premake) against gnu make: cmake and premake are meta-build systems. I’m not gonna start explaining in a boring post how meta build systems work, you could search the web for an excellent article instead.

Ps. If you get interested in using a meta build system for your project, I suggest giving premake a try.On 16 ??? 2013, at 8:03 ?.?., Andrew Havens wrote:

> Yeah, I’m not interested in using XCode either. I’d rather not depend on an IDE. I’ve got a Makefile for automating the compile task. I’ve seen other projects use cmake, but I’m not familiar with what makes it different/better than make.
> 
> The pkg-config and sdl-config look awfully similar?what’s the difference? Why would I want to use sdl-config instead?
> 
> –Andrew
> 
> On October 15, 2013 at 7:29:14 PM, T. Joseph Carter (tjcarter at [spiritsubstance.com](http://spiritsubstance.com)) wrote:
> 
> > A good start for SDL 2.0 would be to look at sdl2-config (or the  
> > equivalent pkg-config if you’re using that?)
> > 
> > The --cflags and --libs args are probably going to help a lot.
> > 
> > Simple incantation:
> > 
> > gcc -o example example.c `sdl2-config --cflags --libs`
> > 
> > If you’re going to write more complex code (and you will), you’ll  
> > need a build system. I suggest eschewing the traditional make(1) in  
> > favor of cmake. You could also set up XCode for SDL development, but  
> > I can’t really help with that. I have a hate/hate relationship with  
> > XCode. 😉
> > 
> > Joseph
> > 
> > On Mon, Oct 14, 2013 at 10:58:28AM -0700, Andrew Havens wrote:
> > 
> > > I already did. The only thing I used was:
> > > 
> > > gcc example.c
> > > 
> > > I’m not sure which files/directories/libraries or whatever to link to or include.
> > 
> > * * *
> > 
> > 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)
> 
> * * *
> 
> 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:** ![T\_Joseph\_Carter](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/t_joseph_carter/32/2525_2.png) [@T\_Joseph\_Carter](https://discourse.libsdl.org/u/T_Joseph_Carter)\
**Post date:** [October 16, 2013, 10:44pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/13 "2013-10-16T22:44:04Z")

</div>

First the easy answer: Lots of libraries began shipping themselves  
with \*-config programs. They all took basically the same args,  
–cflags and --libs. They were so similar and so common that someone  
got a brilliant idea: let’s produce ONE program, call it pkg-config,  
that does it in a common, standard way.

So they’re basically the same thing. If you use pkg-config, it  
becomes absolutely trivial to write a configure test for a library.

Now?

The limitations of make-----------------------

CMake isn’t necessarily better than make for what make does. Well,  
except that telling make about your source code’s header dependencies  
in an automatic fashion is not as trivial as we’d like.

It is better than make for what it does NOT do, however. If you look  
at a pristine SDL source tree, it contains no makefiles. The reason  
is that it doesn’t know what to build, what features to include, etc.

CMake and premake exist to solve that problem. 🙂 The alternative  
are autoconf/automake/etc., and these are considered standard tools.

## Why autotools suck

(Sorry in advance for the novel?)

The standard way to get those on UNIXy systems involves running a  
shell script, ./configure, which generates the makefiles using a  
macro language called m4. Basically imagine if C/C++ preprocessor  
directives like #include and #ifdef were a full scripting language  
unto themselves for generating C/C++ source. Yikes. 🙂

But you can’t just write a configure script, because it too must be  
generated using m4 and other things by running a program called  
autoconf. And all of that is assuming you’re just writing a simple  
program. If you’re writing a library, or you want to avoid writing  
messy Makefile’s, you use another layer on top of that called  
automake. Same deal, only it kind of generates input for autoconf.

Of course all of these may pull in dependencies on UNIX programs like  
sed, awk, and sometimes a whole scripting programming infrastructure  
called perl. In fact, if you want to build a dynamic library in an  
intelligent fashion, you’re kind of best off using another add-on  
called libtool. Whether or not libtool constitutes doing something  
in an intelligent fashion is a matter of some debate, but what’s not  
up for debate is that it DOES bring in a dependency on perl.

You may also have a dependency on stuff like pkg-config, which isn’t  
really a classic UNIX “standard”, but it makes configure test writing  
so easy that it’s very common. And often, then you go and write the  
fallback if pkg-config is NOT installed. But not always.

And if all systems were UNIX, the dependencies aren’t a big deal  
because? well, you’ve got them. But Bourne shell is a language, m4  
is a language, perl is a language, awk is a language, and sed is kind  
of almost a language. 😉 (Basically, it’s mini like a mini subset  
of vi’s predecessor, ed. Think MS-DOS EDLIN, but for working with  
stdin/stdout.)

You’ve got to know about three languages, in addition to the one  
you’re writing your code with, in order to compile it. And if there  
is a bug in your build system, you might need to know all of them!

It’s also not conducive to using an IDE. Any IDE. If you’re using  
that stinking heap of legacy crap left over from the 1970s, your  
development environment is the UNIX shell. Even if you use an IDE  
that cleverly tries to generate automake-compatible stuff in the  
background, I promise you, you WILL be using the command line to sort  
out your projects sooner or later.

## Why CMake is better but not perfect

ONE language. The CMake interpreter has most of the features needed  
to reproduce all of the above autotools stuff built-in. It can build  
static libraries, shared libraries, packages, and even Mac frameworks  
and app bundles. Languages and compilers are just structures  
defining variables and a few test to find the appropriate compilers  
and whatnot for using that language on your system.

It has the same sort of include path setup autoconf/automake use, to  
find cmake macros/plugins, but these are all written in cmake’s  
single language.

You’re not forced to break up your project’s build files all over the  
tree. You can make your build as modular as you want, or not, as you  
choose. While it’s technically possible to do that with make, it’s  
considered doing it wrong. 🙂 There is no recursive make, nor is  
there need for it.

And dependencies? You’ve got one: CMake itself. That, your  
compiler, and your linker are all you need. Plus, CMake CAN generate  
make, MSVC, and XCode project files if you want it to. No IDE does  
(nor likely realistically could) read and write CMakeLists.txt (the  
CMake equivalent of a Makefile, ./configure, and everything), but an  
IDE could at least read that file and figure out what was part of  
your project easily enough.

## Other alternatives

There’s a few. SCons, premake, others? But it’s kind of like  
alternatives for Subversion and CVS: There are many, but git has kind  
of risen to the top. Almost to the point that CVS and Subversion are  
considered inferior alternatives to git, whereas Mercurial would be  
considered fairly comparable.

CMake hasn’t reached that level of prominence. Autotools are still  
the standard, even if CMake is simply a better choice. But there  
isn’t a perfect solution out there that meets everyone’s needs. When  
there is, there will be much rejoicing. 🙂

Joseph

On Tue, Oct 15, 2013 at 10:03:58PM -0700, Andrew Havens wrote:

> Yeah, I’m not interested in using XCode either. I’d rather not depend on an IDE. I’ve got a Makefile for automating the compile task. I’ve seen other projects use cmake, but I’m not familiar with what makes it different/better than make.
> 
> The pkg-config and sdl-config look awfully similar?what’s the difference? Why would I want to use sdl-config instead?

---

<div class="post-metadata">

**Author:** ![Andrew\_Havens](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/andrew_havens/32/2534_2.png) [@Andrew\_Havens](https://discourse.libsdl.org/u/Andrew_Havens)\
**Post date:** [October 16, 2013, 11:00pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/14 "2013-10-16T23:00:24Z")

</div>

Thanks Joseph, that was quite helpful. There was a lot of jargon in there that I’ve seen before, but wasn’t sure how it all came together until now.

So that reminded me of another, similar question that I was planning to ask:

What is the best way to organize a C project for distributing to multiple platforms? I’m planning on building a command-line tool with C that uses SDL that will be distributed to lots of different OSes. I’d rather not require that SDL already be installed, but find a way to distribute it with my program. It would be even better if my users didn’t have to compile anything because it was “precompiled”. How can I simplify the installation process for my users and account for the variations in platforms?

Thanks,

Andrew HavensOn October 16, 2013 at 3:44:08 PM, T. Joseph Carter (tjcarter at [spiritsubstance.com](http://spiritsubstance.com)) wrote:

First the easy answer: Lots of libraries began shipping themselves  
with \*-config programs. They all took basically the same args,  
–cflags and --libs. They were so similar and so common that someone  
got a brilliant idea: let’s produce ONE program, call it pkg-config,  
that does it in a common, standard way.

So they’re basically the same thing. If you use pkg-config, it  
becomes absolutely trivial to write a configure test for a library.

Now?

## The limitations of make

CMake isn’t necessarily better than make for what make does. Well,  
except that telling make about your source code’s header dependencies  
in an automatic fashion is not as trivial as we’d like.

It is better than make for what it does NOT do, however. If you look  
at a pristine SDL source tree, it contains no makefiles. The reason  
is that it doesn’t know what to build, what features to include, etc.

CMake and premake exist to solve that problem. 🙂 The alternative  
are autoconf/automake/etc., and these are considered standard tools.

## Why autotools suck

(Sorry in advance for the novel?)

The standard way to get those on UNIXy systems involves running a  
shell script, ./configure, which generates the makefiles using a  
macro language called m4. Basically imagine if C/C++ preprocessor  
directives like #include and #ifdef were a full scripting language  
unto themselves for generating C/C++ source. Yikes. 🙂

But you can’t just write a configure script, because it too must be  
generated using m4 and other things by running a program called  
autoconf. And all of that is assuming you’re just writing a simple  
program. If you’re writing a library, or you want to avoid writing  
messy Makefile’s, you use another layer on top of that called  
automake. Same deal, only it kind of generates input for autoconf.

Of course all of these may pull in dependencies on UNIX programs like  
sed, awk, and sometimes a whole scripting programming infrastructure  
called perl. In fact, if you want to build a dynamic library in an  
intelligent fashion, you’re kind of best off using another add-on  
called libtool. Whether or not libtool constitutes doing something  
in an intelligent fashion is a matter of some debate, but what’s not  
up for debate is that it DOES bring in a dependency on perl.

You may also have a dependency on stuff like pkg-config, which isn’t  
really a classic UNIX “standard”, but it makes configure test writing  
so easy that it’s very common. And often, then you go and write the  
fallback if pkg-config is NOT installed. But not always.

And if all systems were UNIX, the dependencies aren’t a big deal  
because? well, you’ve got them. But Bourne shell is a language, m4  
is a language, perl is a language, awk is a language, and sed is kind  
of almost a language. 😉 (Basically, it’s mini like a mini subset  
of vi’s predecessor, ed. Think MS-DOS EDLIN, but for working with  
stdin/stdout.)

You’ve got to know about three languages, in addition to the one  
you’re writing your code with, in order to compile it. And if there  
is a bug in your build system, you might need to know all of them!

It’s also not conducive to using an IDE. Any IDE. If you’re using  
that stinking heap of legacy crap left over from the 1970s, your  
development environment is the UNIX shell. Even if you use an IDE  
that cleverly tries to generate automake-compatible stuff in the  
background, I promise you, you WILL be using the command line to sort  
out your projects sooner or later.

## Why CMake is better but not perfect

ONE language. The CMake interpreter has most of the features needed  
to reproduce all of the above autotools stuff built-in. It can build  
static libraries, shared libraries, packages, and even Mac frameworks  
and app bundles. Languages and compilers are just structures  
defining variables and a few test to find the appropriate compilers  
and whatnot for using that language on your system.

It has the same sort of include path setup autoconf/automake use, to  
find cmake macros/plugins, but these are all written in cmake’s  
single language.

You’re not forced to break up your project’s build files all over the  
tree. You can make your build as modular as you want, or not, as you  
choose. While it’s technically possible to do that with make, it’s  
considered doing it wrong. 🙂 There is no recursive make, nor is  
there need for it.

And dependencies? You’ve got one: CMake itself. That, your  
compiler, and your linker are all you need. Plus, CMake CAN generate  
make, MSVC, and XCode project files if you want it to. No IDE does  
(nor likely realistically could) read and write CMakeLists.txt (the  
CMake equivalent of a Makefile, ./configure, and everything), but an  
IDE could at least read that file and figure out what was part of  
your project easily enough.

## Other alternatives

There’s a few. SCons, premake, others? But it’s kind of like  
alternatives for Subversion and CVS: There are many, but git has kind  
of risen to the top. Almost to the point that CVS and Subversion are  
considered inferior alternatives to git, whereas Mercurial would be  
considered fairly comparable.

CMake hasn’t reached that level of prominence. Autotools are still  
the standard, even if CMake is simply a better choice. But there  
isn’t a perfect solution out there that meets everyone’s needs. When  
there is, there will be much rejoicing. 🙂

Joseph

On Tue, Oct 15, 2013 at 10:03:58PM -0700, Andrew Havens wrote:

> Yeah, I’m not interested in using XCode either. I’d rather not depend on an IDE. I’ve got a Makefile for automating the compile task. I’ve seen other projects use cmake, but I’m not familiar with what makes it different/better than make.
> 
> The pkg-config and sdl-config look awfully similar?what’s the difference? Why would I want to use sdl-config instead?

* * *

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:** ![Jared\_Maddox](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@Jared\_Maddox](https://discourse.libsdl.org/u/Jared_Maddox)\
**Post date:** [October 17, 2013, 3:51am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/15 "2013-10-17T03:51:17Z")

</div>

> Message-ID: Content-Type: text/plain; charset="utf-8"
> 
> Thanks Joseph, that was quite helpful. There was a lot of jargon in there  
> that I’ve seen before, but wasn’t sure how it all came together until now.
> 
> So that reminded me of another, similar question that I was planning to  
> ask:
> 
> What is the best way to organize a C project for distributing to multiple  
> platforms? I’m planning on building a command-line tool with C that uses SDL  
> that will be distributed to lots of different OSes. I’d rather not require  
> that SDL already be installed, but find a way to distribute it with my  
> program. It would be even better if my users didn’t have to compile anything  
> because it was “precompiled”. How can I simplify the installation process  
> for my users and account for the variations in platforms?
> 
> Thanks,
> 
> Andrew Havens

I’ve got a possible answer to that. The normal response when  
SDL\_Init() fails is to pop an error, and quit. However, that isn’t  
strictly necessary. If you’ve stored the appropriate files inside your  
program then you can simply them out and try again, possibly with an  
alert and “click OK or CANCEL” choice. The prep work for this is  
mostly restrained to copying the files in question into a C array  
(something which a quick console app can do in probably 500 or so  
lines of code, even if you use comedic amounts of blank lines like I  
do), writing the length of that array into a variable (note: both the  
array and the size should go in the same C file!), and sticking  
“extern” declarations for the array and size into a C header. Once  
that’s done, it’s a matter of entry-level file IO to get the file(s)  
out to disk.

If you do go this route, I’d suggest command-line options to output  
the stored files as a generally good idea. Having the source available  
through the same method for those who DO want to compile it themselves  
would be even better.

There are, still, some issues. Some OSes (most \*nixen, I believe)  
require files to be marked as executable before they actually can be  
treated as executable. Thus, you’ll either need to do that (a likely  
separate operation for each distinct platform), or to pop up an alert  
asking the user to do that (as long as the program walks the user  
through the process, this shouldn’t be a problem: you might even be  
able to justify some archive files instead of the “raw” dynamic  
libraries). Some (e.g. some of the Android-based B&N Nook devices)  
restrict where you can write files, which may interfere with this:  
you’ll want to make static-linked executables if you target those  
devices. And absolutely remember to ship the right file(s) inside your  
executable; a Window dll on a Damn Small Linux distro that doesn’t  
have WINE is useless in almost every way: I would suggest a distinct  
compilation directory for every target for precisely this reason. The  
code may all go in one place (or one set of places, since it’ll be  
both your program and SDL), but the executables should absolutely be  
sorted by target, that way you can perform your “distro-package”  
command modularly, iterating over the bits that need it without having  
to hand-code for each target.

Past that, remember to keep the core of your application as abstracted  
away from the platform that it’s running on as possible (or, to put it  
another way, target SDL as much as you can, and the platform that SDL  
is sitting on as little as you can). Where not possible,  
compartmentalize as much as possible. For the bits and pieces that are  
left over (and also inside those “black boxes” that you hide the  
platform stuff in), use comments to document the goal of the whole  
thing, both before you started coding, and after you finished  
debugging. Ideally, you should be able to compile the core of your  
program without pulling in anything that isn’t part of the language’s  
standard library, and finish the program by compiling a handful of  
“foundation” files that deal with the platform-specific stuff.\> Date: Wed, 16 Oct 2013 16:00:24 -0700

> From: Andrew Havens   
> To: SDL Development List , “T. Joseph Carter”  
> Subject: Re: [SDL] Getting started with SDL in C

---

<div class="post-metadata">

**Author:** ![Driedfruit](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/f14d63/32.png) [@Driedfruit](https://discourse.libsdl.org/u/Driedfruit)\
**Post date:** [October 17, 2013, 12:18am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/16 "2013-10-17T00:18:06Z")

</div>

> ## The limitations of make

Completely off-topic, but make is not just a build tool, it’s an  
absolutely brilliant dependency graph resolver, with a very simple, yet  
powerful syntax.

I use make for all kinds of stuff, compiling LESS into CSS, generating  
transparent PNGs, flashing microcontrollers, etc.

It’s good.

> CMake

Unless you really really want to support project files for various  
IDEs, I’d stick with autotools. They work on UNIXes (including Mac OS  
X), and on Windows with cygwin/mingw/mingw-w64.

CMake is both loved and hated on this very list (for example), so it’s  
definitely not a “final solution”.

Just my 2 cents.On Wed, 16 Oct 2013 15:44:04 -0700 “T. Joseph Carter” wrote:

–  
driedfruit

---

<div class="post-metadata">

**Author:** ![Jared\_Maddox](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@Jared\_Maddox](https://discourse.libsdl.org/u/Jared_Maddox)\
**Post date:** [October 19, 2013, 4:01am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/17 "2013-10-19T04:01:30Z")

</div>

When did everyone else get this message? On the mailinglist archives  
it’s dated for the 16th, in the digest it’s dated for the 17th, and it  
was placed between two messages dated for the 18th!\> Date: Thu, 17 Oct 2013 04:18:06 +0400

> From: Driedfruit   
> To: sdl at [lists.libsdl.org](http://lists.libsdl.org)  
> Subject: Re: [SDL] Getting started with SDL in C  
> Message-ID: \<20131017041806.2876e2cc at [driedfruit.mindloop.net](http://driedfruit.mindloop.net)\>  
> Content-Type: text/plain; charset=US-ASCII
> 
> On Wed, 16 Oct 2013 15:44:04 -0700 “T. Joseph Carter” wrote:
> 
> > ## The limitations of make
> 
> Completely off-topic, but make is not just a build tool, it’s an  
> absolutely brilliant dependency graph resolver, with a very simple, yet  
> powerful syntax.

Oh, I agree. If you were to alter the syntax to support return values  
(ala logic languages) and “calls”, + a way to provide “call targets”  
from external sources, in addition to the language-native sources,  
than maybe it would even work as the foundation of a meta-build  
system. I went to the bother of tracking down a description of the  
algorithm in the hope that I eventually will do this.

Not today, though.

> > CMake
> 
> Unless you really really want to support project files for various  
> IDEs, I’d stick with autotools. They work on UNIXes (including Mac OS  
> X), and on Windows with cygwin/mingw/mingw-w64.
> 
> CMake is both loved and hated on this very list (for example), so it’s  
> definitely not a “final solution”.

And this is where we get back on-topic, because from my experience the  
autotools suite and it’s various characteristic hangers-on are  
despised more than CMake. In fact, generalized hate for autotools is  
the reason why CMake is so big right now. See Andrew Havens’s rant  
“Why autotools suck”, earlier in this discussion. I don’t consider a  
“fuller” C/C++ preprocessor to be all that scary of a thing, but I  
would also never even consider such a thing to be a serious contender  
for a meta-build language. As an analogy, a “full-featured set” of  
chainsaw, tweezers, and glue is not what I would consider a good  
carpentry tool set. A scripting language could work, but it should be  
such in the same sense that Javascript is, not in the “character  
editing” sense that sed & similar are, the language shouldn’t need  
anything other than plugins and itself, and certainly shouldn’t be  
interwoven with the data it’s going to be acting on. And if it has to  
be an as-text language instead of a compiled or “compiled” language,  
then at least it should be done in a standardized shell language  
instead of some random preprocessor language that doesn’t get used for  
other purposes. CMake might not kill autotools, but autotools will  
assuredly die.

In conclusion, if autotools was actually all that good of a solution,  
as opposed to just a common solution, then by this point it would have  
started to become a standard tool on even Windows, much like Git.  
Make has extended it’s presence to every platform that I’ve look at  
compiler technology for, including Windows (where MS uses it’s  
extended version to compile the OS), despite the fact that all three  
major branches that I know of (GNU, BSD, and MS) have slightly  
different syntax for their conditionals. That the autotools system  
hasn’t found the same level of success speaks volumes.

---

<div class="post-metadata">

**Author:** ![T\_Joseph\_Carter](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/t_joseph_carter/32/2525_2.png) [@T\_Joseph\_Carter](https://discourse.libsdl.org/u/T_Joseph_Carter)\
**Post date:** [October 19, 2013, 4:55am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/18 "2013-10-19T04:55:32Z")

</div>

> And this is where we get back on-topic, because from my experience the  
> autotools suite and it’s various characteristic hangers-on are  
> despised more than CMake. In fact, generalized hate for autotools is  
> the reason why CMake is so big right now. See Andrew Havens’s rant  
> “Why autotools suck”, earlier in this discussion.

Did Andrew write such a thing? I don’t recall. I did, just a couple  
of messages ago, however. 🙂

But it’s worth pointing out that I don’t hate the autotools either.  
I understand them, and I was even able to pick up poking at them  
after more than a decade of not even touching that monstrosity.

But it is woefully complex?too much so for what it does?and it is  
absolutely daunting for new users. Even grizzled white-bearded  
programmers who fully understand how automake and autoconf work (and  
how they work together) are still grateful for helpers like  
autoproject to generate a vaguely GNUish build tree tree simply  
because it saves them time and energy.

> I don’t consider a  
> “fuller” C/C++ preprocessor to be all that scary of a thing, but I  
> would also never even consider such a thing to be a serious contender  
> for a meta-build language. As an analogy, a “full-featured set” of  
> chainsaw, tweezers, and glue is not what I would consider a good  
> carpentry tool set. A scripting language could work, but it should be  
> such in the same sense that Javascript is, not in the “character  
> editing” sense that sed & similar are, the language shouldn’t need  
> anything other than plugins and itself, and certainly shouldn’t be  
> interwoven with the data it’s going to be acting on. And if it has to  
> be an as-text language instead of a compiled or “compiled” language,  
> then at least it should be done in a standardized shell language  
> instead of some random preprocessor language that doesn’t get used for  
> other purposes. CMake might not kill autotools, but autotools will  
> assuredly die.

A scripting language DOES work, if it has all the right components as  
built-in tools. Personally, I think CMake spends far too much time  
worrying about how to generate MSVC, XCode, etc. project files. If I  
were writing for the Mac or iOS app stores, obviously I’d have to use  
CMake over autotools. It just wouldn’t be an option, because you  
have to submit XCode projects to Apple.

I _hate_ XCode. Oh, I’m sure it’s a perfectly fine development tool,  
and frankly I _wish_ I had a better debugging tool than gdb at the  
command line when working on modern multi-threaded code. But no GUI  
IDE is going to work for me. These days, it’s hard to even imagine  
something like the old Borland text-based IDE. The standard UNIX  
shell is simply more powerful for any development task, and I am very  
comfortable working in my 120x30 window? 🙂

> In conclusion, if autotools was actually all that good of a solution,  
> as opposed to just a common solution, then by this point it would have  
> started to become a standard tool on even Windows, much like Git.  
> Make has extended it’s presence to every platform that I’ve look at  
> compiler technology for, including Windows (where MS uses it’s  
> extended version to compile the OS), despite the fact that all three  
> major branches that I know of (GNU, BSD, and MS) have slightly  
> different syntax for their conditionals. That the autotools system  
> hasn’t found the same level of success speaks volumes.

It does.

But also that the many competitors have not either does as well.  
CMake is out there. SCons is out there. There’s also premake, whose  
concept I’d love if it weren’t so ? MSVC focused.

I really wanted to love premake because of Lua. Lua’s something that  
a lot of people around here will be familiar with because it is used  
rather prominently in a couple of major games, but it is a full and  
complete language in and of itself. The only thing I’ve seen smaller  
than Lua is perhaps some implementations of Ruby. And Frankly, Lua  
is more efficient even though Ruby is more popular. 🙂

Lua has most of what you’d need to write a good meta-build system out  
of the box, and most of what’s missing is trivial to add.

How trivial? Well, after 6-7 years of not even looking at a gcc  
command line, it took me 24 hours to learn to understand Lua enough  
to implement fully native 2, 3, and 4 component float vectors in Lua.  
Probably was reinventing the wheel there. And I mean fully native  
both in Lua where they behaved like any built-in data type, and also  
in C where they were simply arrays. Single or double precision float  
depended on your compiler settings.

36 hours after that, I’d basically implemented a basic SDL setup/loop  
framework around the interpreter put vertex-shaded triangle meshes  
into a list in Lua and have a very simple C based renderer draw the  
list every frame. You could actually modify this structure at  
runtime and see the results of your change immediately.

That’s as far as I got with it, and I doubt I even have the code tree  
laying around years later. ☹

But, if I could do _that_ with Lua being rusty after years of not  
writing a single line of code, surely someone else could make Lua  
figure out which header defines a function, or what headers a bit of  
source code depends upon, or where libraries are located and how to  
compile against them. And the resulting syntax out to be easier and  
cleaner than CMake uses. And mountains more reasonable than anything  
you could come up with using autotools.

But I feel the same way about MSVC that I do about XCode and for much  
the same reason.

JosephOn Fri, Oct 18, 2013 at 11:01:30PM -0500, Jared Maddox wrote:

---

<div class="post-metadata">

**Author:** ![Jonas\_Kulla](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@Jonas\_Kulla](https://discourse.libsdl.org/u/Jonas_Kulla)\
**Post date:** [October 19, 2013, 11:46am UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/19 "2013-10-19T11:46:58Z")

</div>

2013/10/19 Jared Maddox

> In conclusion, if autotools was actually all that good of a solution,  
> as opposed to just a common solution, then by this point it would have  
> started to become a standard tool on even Windows, much like Git.  
> Make has extended it’s presence to every platform that I’ve look at  
> compiler technology for, including Windows (where MS uses it’s  
> extended version to compile the OS), despite the fact that all three  
> major branches that I know of (GNU, BSD, and MS) have slightly  
> different syntax for their conditionals. That the autotools system  
> hasn’t found the same level of success speaks volumes.

Not all platforms are made the same. Autotools is very vividly written with  
a Unix  
system in mind, so to me it’s no wonder it couldn’t ever catch on on a  
platform  
where forking a process takes ages and configure scripts take 10 times the  
actual  
compile time to run. Also, no bash.

---

<div class="post-metadata">

**Author:** ![Juan\_Manuel\_Borges\_C](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/a4c791/32.png) [@Juan\_Manuel\_Borges\_C](https://discourse.libsdl.org/u/Juan_Manuel_Borges_C)\
**Post date:** [October 19, 2013, 12:14pm UTC](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048/20 "2013-10-19T12:14:47Z")

</div>

“Make Project” a.k.a. mkproject is for that kind of people that does not  
want to mess with a point & click integrated development environment, but  
rather stick to configuration files and scripting them,  
[Google Code Archive - Long-term storage for Google Code Project Hosting.](https://code.google.com/p/makeproject/) . Currently uses autoconf et friends  
as backend but can generate you a customized starting project in a line. It  
can ./configure; make; make install from start, but to keep your  
development you have to play with configure.ac, and Makefile.am files. The  
documentation in this subjects are dense, but the real usage of them is  
just to change/add source files to Makefile.am, and if you rely on  
pkg-config handling dependencies is also as easy as adding the package  
module name to DEP\_MODULES in configure.ac. Advantages over plain  
Makefiles, what just i told + it generates a more professional/complete  
plain Makefiles that offer make; make clean; make dist (tarballs); make  
distcheck (checks correct installation _pro_); make tests (any easy checks  
that you can configure in Makefile.am too), and so on, the lists don’t  
stop, keeping the said, you just change/add source files and module names  
to deps, at a minimal view.

As much as I consider autoconf/automake rapid itself, I consider mkproject  
a rapid autoconf/automake tool for the setup part, that found missing in  
the autoconf/automake stack,

2 cents, if you find it useful let me know.On Sat, Oct 19, 2013 at 1:46 PM, Jonas Kulla wrote:

> 2013/10/19 Jared Maddox
> 
> > In conclusion, if autotools was actually all that good of a solution,  
> > as opposed to just a common solution, then by this point it would have  
> > started to become a standard tool on even Windows, much like Git.  
> > Make has extended it’s presence to every platform that I’ve look at  
> > compiler technology for, including Windows (where MS uses it’s  
> > extended version to compile the OS), despite the fact that all three  
> > major branches that I know of (GNU, BSD, and MS) have slightly  
> > different syntax for their conditionals. That the autotools system  
> > hasn’t found the same level of success speaks volumes.
> 
> Not all platforms are made the same. Autotools is very vividly written  
> with a Unix  
> system in mind, so to me it’s no wonder it couldn’t ever catch on on a  
> platform  
> where forking a process takes ages and configure scripts take 10 times the  
> actual  
> compile time to run. Also, no bash.
> 
> * * *
> 
> 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)

[Next page](https://discourse.libsdl.org/t/getting-started-with-sdl-in-c/20048.md?page=2)
