尝试用C语言编译下面的代码(我不太擅长它)并得到Address boundary error。似乎变量未初始化。

all:
  gcc -Wall -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include test.c `pkg-config --cflags dbus-1` `pkg-config --libs dbus-1 gio-unix-2.0`


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <glib-2.0/glib.h>

int main (){

    GIOStream stream;
    GDBusConnectionFlags flags = G_DBUS_CONNECTION_FLAGS_NONE;
    GError *gerr = NULL;

    GDBusConnection * gcon = g_dbus_connection_new_sync(&stream,
            NULL,
            flags,
            NULL,
            NULL,
            &gerr);

    return 0;
}

以下是GDBusConnectionGIOStream的文档。
我不明白密码怎么了。你能解释一下吗?

最佳答案

再过几天,我发现下面的方法有效:

GInputStream * ginput = g_memory_input_stream_new();
    GOutputStream * goutput = g_memory_output_stream_new (NULL, 0, realloc, free);
    GIOStream * stream = g_simple_io_stream_new(ginput, goutput);

    GDBusConnectionFlags flags = G_DBUS_CONNECTION_FLAGS_NONE;
    GError* gerr = NULL;

    GDBusConnection * gcon = g_dbus_connection_new_sync(stream,
            NULL,
            flags,
            NULL,
            NULL,
            &gerr);
    if (gerr){
        printf(gerr->message, "%s");
    }

关于c - GIO库C:DBUS | GIOStream和GIOConnection,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47506193/

10-10 02:53