Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
41 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

"Wow, cool! My First Linux Program! But...How do I compile it?" Ahhh...I'm so glad you asked, my son (or daughter).

Linux mainly uses a compiler called "gcc" (GNU C Compiler). It is probably the most ANSI-C Compilant compilers I've ever used. Now, wanna compile your program? Go to a shell, cd to your directory and type:

gcc linux-helloworld.c

It will generate a file called a.out so, what I expect you to do next, is type ./a.out and see the results. Happy? Heh, well I was. There are many more options you can send to gcc, I will cover a few here.

-c will compile the code to an object file, not an executable.

-o will create the file as . For example, -o my_app will compile your source into an executable called my_app, which you can then call by typing ./my_app.

-l will link with a library. For SDL, -lSDL will link to the library. See other library documentations for help.

-L will tell the path that the libraries are located in. -L/usr/lib will tell gcc that they are in /usr/lib.

-O will turn optimization on and off. The level of optimization is 1 - 6. 1 is the lowest, while 6 is the highest.

-pendantic -W -Wall should be used if you want gcc to tell you about your coding (dis)abilities.

So, an example program that is compiled with SDL would look a bit like this.

gcc `sdl-config --cflags` -W -Wall -O2 program.c -o game -lSDL -lpthread

Wow! It compiled! How cool is that? Well I think it is very cool. If you're confused at all of the other parameters, then it's ok. Most of them are SDL specific and will be covered in later tutorials. But...wouldn't it really suck to type in all of that every time you want to compile? What if you had a few hundred .c files? Wouldn't it take very long? Along comes Make to the rescue!



Page 5

Contents
  Introduction
  Page 2
  Page 3
  Page 4
  Page 5
  Page 6
  Conclusion

  Source code
  Printable version
  Discuss this article

The Series
  Part 1