I want to make class by using C GObject lib in Codeblocks. So I have 2 classes: A.h and A.c But when i include gobject lib like this:
#include <glib-2.0/gobject/gobject.h>
It gives me an error:
Only <glib-object.h> can be included directly.
Because this file contains these lines:
#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
#error "Only <glib-object.h> can be included directly."
#endif
A.h:
#ifndef A_H
#define A_H
#include <glib-2.0/gobject/gobject.h>
//It's only declaring an class called A
typedef struct _AClass AClass;
typedef struct _A A;
struct _AClass {
//Always Derived from GObjectClass class
GObjectClass parent_instance;
}
struct _A{
//Always Derived from GObject class
GObject parent_instance;
}
#endif // A_H
A.c:
#include "/home/alex/GObject_Tutorial/include/A.h"
//It's defining a class called A
G_DEFINE_TYPE(A, aObj, G_TYPE_OBJECT);
I think the only way to include these libraries is to add them to local folder and include like (but maybe there is another way):
#include "gobject.h"
Thank you. So my total answer: We don't include only gobject/gobject.h, because glib-object.h is aggregator and it contains these all libraries to provide a creating of gobject-class. My steps:
1) Find where are the libs in glibs using:
pkg-config --cflags --libs gobject-2.0
So, I've got result (in your case it can be different):
-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lgobject-2.0 -lglib-2.0
2) Then in code::blocks Project->Build Options->Compiler Settings->Other Options
3) Copy this line (-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include) in text field
4) Copy to Project->Build Options->Linker Settings->Other Linker Options this line (-lgobject-2.0 -lglib-2.0)
5) Build
6) Hooray! It works, Thanks to everyone :)