尝试在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;
}
以下是GDBusConnection和GIOStream的文档。 我无法理解代码有什么问题。你能解释一下吗?
答案 0 :(得分:0)
经过几次,我发现以下作品:
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");
}