The best way to start learning a programming language is by writing a program.
How to edit and compile the program?
That depends on the compiler you are using.
First of all, you should write a simple program using C language.
This is a simple program:
1 2 3 4 5 6 7 8 9 10 11 12 | #include <gtk/gtk.h> #include int main( int argc, char *argv[] ) { GtkWidget *window; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); gtk_main (); return 0; } |
Now about the compilers:
gcc is the “GNU” C Compiler
g++ is the “GNU C++ compiler
cc is the “Sun” C Compiler
CC is the “Sun” C++ compiler
I will use gcc because is a C program.
When it contains Xlib graphics routines the command is :
1 | gcc myprogram.c -o myprogram -lX11 |
( see -l = link and X11 is Xlib).
What is pkg-config?
This is a helper tool.
It helps you insert the correct compiler options on the command line.
Your application can use something like this :
1 | gcc -o test test.c `pkg-config --libs --cflags glib-2.0` |
How did it work?
When a library is installed a .pc file should be included.
This file tells us that libraries can be found in /usr/local/lib
and headers in /usr/local/include
.
But first of all, you must install the libs.
On my example I need this gtk2-devel.i686, so I use :
1 2 3 4 | yum search gtk2-devel Loaded plugins: presto, refresh-packagekit ============= Matched: gtk2-devel ================= gtk2-devel.i686 : Development files for GTK+ |
And I compile with this:
1 | $gcc `pkg-config --cflags --libs gtk+-2.0` -o app app.c |
And the result is: