gpt4 book ai didi

c - GIO 库 C : DBUS | GIOStream and GIOConnection

转载 作者:太空宇宙 更新时间:2023-11-04 04:20:23 25 4
gpt4 key购买 nike

尝试用 C 编译以下代码(我不是很擅长)并得到地址边界错误。变量似乎未初始化。

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 .我不明白代码有什么问题。你能解释一下吗?

最佳答案

再过一段时间后,我发现以下工作:

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 and GIOConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47506193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com