【发布时间】:2013-08-18 16:24:11
【问题描述】:
我想在 Codeblocks 中使用 C GObject lib 来上课。所以我有 2 个课程:A.h 和 A.c 但是当我像这样包含 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"
【问题讨论】:
标签: c codeblocks gobject