Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Started with C development and GTK+

Tags:

gcc

gtk

I'm really a Python developer exclusively, but I'm making my first foray into C programming now, and I'm having a lot of trouble getting started. I can't seem to get the hang of compilation and including libraries. At this point, I'm just identifying the libraries that I need and trying to compile them with a basic "hello, world" app just to make sure that I have my environment setup to do the actual programming.

This is a DBus backend application that will use GIO to connect to DBus.

#include <stdlib.h>
#include <gio/gio.h>

int 
main (int argc, char *argv[])
{
    printf("hello, world");
    return 0;
}

Then, I try to compile:

~$ gcc main.c
main.c:2:21: fatal error: gio/gio.h: No such file or directory
 #include <gio/gio.h>

I believe that I've installed the correct packages as indicated here, and gio.h exists at /usr/include/glib-2.0/gio/gio.h.

I found a command online to add a search directory to gcc, but that resulted in other errors:

~$ gcc -I /usr/include/glib-2.0/ main.c 
In file included from /usr/include/glib-2.0/glib/galloca.h:34:0,
                 from /usr/include/glib-2.0/glib.h:32,
                 from /usr/include/glib-2.0/gobject/gbinding.h:30,
                 from /usr/include/glib-2.0/glib-object.h:25,
                 from /usr/include/glib-2.0/gio/gioenums.h:30,
                 from /usr/include/glib-2.0/gio/giotypes.h:30,
                 from /usr/include/glib-2.0/gio/gio.h:28,
                 from main.c:2:
/usr/include/glib-2.0/glib/gtypes.h:34:24: fatal error: glibconfig.h: No such file or directory
 #include <glibconfig.h>
                        ^
compilation terminated.

There has to be some relatively simple method for being able to set some options/variables (makefile?) to automatically include the necessary headers. I'm also going to use Eclipse-CDT or Anjuta as an IDE and would appreciate help to fix the import path (or whatever it's called in C).

Any help is greatly appreciated.

like image 822
fandingo Avatar asked Oct 01 '22 16:10

fandingo


1 Answers

Use pkg-config (and make). See exactly this answer to a very similar question. See also this and that answers. Don't forget -Wall -g flags to gcc ..

You don't need an IDE to compile your code (the IDE will just run some gcc commands, so better know how to use them yourself).

like image 113
Basile Starynkevitch Avatar answered Oct 13 '22 12:10

Basile Starynkevitch