dbus-glib.h里面没有DBusConnection,只有DBusGConnection。

我看了下相关的文档,好像大家写dbus-ding-send.c这个文件的时候用的基本都是DBusConnection.我看了下我dbus-glib.h文件里面,根本就没有DBusConnection这个结构体的定义。是不是后面的DBUS的库更新了?然后把这个函数改名了? #include #include #include static gboolean send_ding(DBusConnection *bus); int main () { GMainLoop *loop; DBusConnection *bus; DBusError error; loop = g_main_loop_new(NULL, FALSE); dbus_error_init (&error); bus = dbus_bus_get(DBUS_BUS_SESSION, &error); if (!bus) { g_warning("连接到D-Bus失败: %s", error.message); dbus_error_free(&error); return 1; } dbus_connection_setup_with_g_main(bus, NULL); g_timeout_add(1000, (GSourceFunc)send_ding, bus); g_main_loop_run(loop); return 0; } static gboolean send_ding(DBusConnection *bus) { DBusMessage *message; message = dbus_message_new_signal("/com/burtonini/dbus/ding", "com.burtonini.dbus.Signal", "ding"); dbus_message_append_args(message, DBUS_TYPE_STRING, "ding!", DBUS_TYPE_INVALID); dbus_connection_send(bus, message, NULL); dbus_message_unref(message); g_print("ding!\n"); return TRUE; } 编译:gcc 03.c `pkg-config --cflags --libs glib-2.0 dbus-1` 报错: 03.c:7: error: expected ‘)’ before ‘*’ token 03.c: In function ‘main’: 03.c:15: error: ‘DBusConnection’ undeclared (first use in this function) 03.c:15: error: (Each undeclared identifier is reported only once 03.c:15: error: for each function it appears in.) 03.c:15: error: ‘bus’ undeclared (first use in this function) 03.c:17: error: ‘DBusError’ undeclared (first use in this function) 03.c:17: error: expected ‘;’ before ‘error’ 03.c:21: error: ‘error’ undeclared (first use in this function) 03.c:37: error: ‘send_ding’ undeclared (first use in this function) 03.c: At top level: 03.c:45: error: expected ‘)’ before ‘*’ token 还是说我的D-BUS版本安错了? 这是我所有的DBUS有关的信息。 rpm -qa | grep dbus dbus-1.2.24-7.el6_3.x86_64 dbus-devel-1.2.24-7.el6_3.x86_64 eggdbus-0.6-3.el6.x86_64 dbus-python-0.83.0-6.1.el6.x86_64 dbus-x11-1.2.24-7.el6_3.x86_64 dbus-c++-0.5.0-0.10.20090203git13281b3.1.el6.x86_64 dbus-doc-1.2.24-7.el6_3.noarch dbus-libs-1.2.24-7.el6_3.x86_64 dbus-glib-0.86-5.el6.x86_64 python-slip-dbus-0.2.20-1.el6_2.noarch dbus-glib-devel-0.86-5.el6.x86_64
网友 1

回答

其他回答
你看的那个例子已经过期了,你想要的头文件已经变成了dbus-glib-lowlevel.h,请参考其他的例子
回答者:网友
我来回答