我想通过在 Codeblocks 中使用 C GObject lib 来上课。所以我有 2 个类:Ah 和 Ac 但是当我像这样包含 gobject lib 时:
#include <glib-2.0/gobject/gobject.h>
它给了我一个错误:
Only <glib-object.h> can be included directly.
因为这个文件包含这些行:
#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
#error "Only <glib-object.h> can be included directly."
#endif
啊:
#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
交流:
#include "/home/alex/GObject_Tutorial/include/A.h"
//It's defining a class called A
G_DEFINE_TYPE(A, aObj, G_TYPE_OBJECT);
我认为包含这些库的唯一方法是将它们添加到本地文件夹并包含类似(但也许还有另一种方法):
#include "gobject.h"