Tag: glib

如何编译基本的D-Bus / glib示例?

我正在尝试学习如何使用带有C绑定的D-Bus。 我以前从未使用过D-Bus。 我正在学习本教程 ,我认为这是官方教程 (Freedesktop.org)。 我已经读过它,直到这个段落给出了第一个示例程序,但不幸的是我在这个页面上没有看到任何关于如何编译它或包含哪些库的指示。 我错过了什么 ? 我的操作系统是Ubuntu 10.04 32bit。 我安装了libdbus-glib-1-dev软件包。 我尝试在源文件的开头添加#include ,并使用 $ gcc -ldbus-1 -I/usr/include/dbus-1.0/ -I/usr/lib/i386-linux-gnu/dbus-1.0/include -o my_dbus.bin my_dbus.c 但我一直都在失败: my_dbus.c: In function ‘main’: my_dbus.c:7:3: error: unknown type name ‘DBusGConnection’ my_dbus.c:8:3: error: unknown type name ‘GError’ … 我是否错过了教程中的一点? 不,你能帮我编译一下这段代码吗? 提前致谢。

什么是gdbus库名称? 技术找到它?

使用Bluez gdbus.h函数需要包含哪些库? 我收到很多gdbus.h函数的undefined reference错误,所以我显然错过了一个库。 *有没有办法(在终端或其他方面)我可以找出头文件使用的库? 例如; 我可以使用locate gdbus.h头文件所在的locate gdbus.h 。 有没有办法可以找出gdbus.h需要什么库? 我目前的pkg-config是: pkg-config –cflags gio-2.0 dbus-glib-1 dbus-1 glib-2.0 gthread-2.0 pkg-config –libs gio-2.0 dbus-glib-1 dbus-1 glib-2.0 gthread-2.0 有了这个,我得到许多未定义的引用,如: agent.c:100:对’g_dbus_send_reply’的未定义引用 agent.c:104:对’g_dbus_send_reply’的未定义引用 agent.c:107:对’g_dbus_send_error’的未定义引用 我错过了什么图书馆?

C调用链表内容的函数

我正在使用GLib来管理链表。 我正在声明2个结构并将它们放在一个链表中,如下所示。 Asteroid asteroid = {0,0,50,50,50} Asteroid asteroids = {0,0,200,200,50}; GList *asteroidList = NULL; asteroidList = g_list_append(asteroidList, &asteroid); asteroidList = g_list_append(asteroidList, &asteroids); 然后我使用以下函数遍历列表和calla函数,将结构绘制为屏幕,如下所示 void drawAsteroids(){ GList *list = asteroidList; while(list != NULL){ printf(“Asteroids”); GList *next = list->next; drawAsteroid(list->data); list = next; } } 绘图function是 void drawAsteroid(void *asteroid){ Asteroid *newAsteroid = (Asteroid *)asteroid; printf(“%d\n”, newAsteroid->xPos); circleRGBA(renderer, […]

如何覆盖GstBin中的handle_message?

试图创建一个子类: mybin.h: #pragma once #include G_BEGIN_DECLS G_DECLARE_DERIVABLE_TYPE(MyBin, my_bin, MY, BIN, GstBin) struct _MyBinClass { GstBinClass parent_class; }; GstElement* my_bin_new(const gchar *name); G_END_DECLS mybin.c: #include “mybin.h” G_DEFINE_TYPE(MyBin, my_bin, GST_TYPE_BIN) static void my_bin_init(MyBin *bin) { } static void my_bin_class_init(MyBinClass *class) { // virtual function overrides go here } GstElement* my_bin_new(const gchar *name) { // ??? } 在my_bin_new()写什么来调用my_bin_class_init() […]

Glib – 来自glib的未定义引用?

我的S程序有问题。 我需要用这个命令编译它: gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 \ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wall -Wextra -g -std=c99 -lm *.c \ -o generator1_1 我有很多这样的错误消息: /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:153: undefined reference to `g_hash_table_lookup’ /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:171: undefined reference to `g_hash_table_insert’ /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:172: undefined reference to `g_array_append_vals’ /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:179: undefined reference to `g_array_append_vals’ /tmp/ccVqEbsM.o: In function `main’: /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:238: undefined reference to `g_hash_table_new_full’ /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:239: undefined reference to `g_hash_table_new_full’ /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:263: undefined […]

Glib内存分配错误

我在ubuntu上使用库libfprint ,我试图通过我的java代码调用一个函数。 API_EXPORTED struct fp_img *fpi_img_new(size_t length) { struct fp_img *img = g_malloc(sizeof(*img) + length); memset(img, 0, sizeof(*img)); fp_dbg(“length=%zd”, length); img->length = length; return img; } 我从我的java代码传递整数值5到此函数。 当我尝试执行上述function时,我遇到以下错误: GLib-ERROR **: /build/buildd/glib2.0-2.30.0/./glib/gmem.c:170: failed to allocate 3077591024 bytes 我在2个不同的ubuntu机器上尝试了相同的代码,但错误仍然相同。 我不知道为什么它试图为24 + 5长度分配这么多字节。 有人能建议我解决吗?

尝试通过g_spawn_async执行shell命令并读取输出

我试图执行一个shell命令(ls / home)并试图读取输出实际上是这个程序的问题? 这是该计划。 #include #include #include #include typedef struct{ int std_in; int std_out; int std_err; }child_fds; gboolean cb_stdout(GIOChannel* channel, GIOCondition condition, gpointer data){ if(condition & G_IO_ERR ){ return TRUE; } if(condition & G_IO_HUP ){ return FALSE; } gsize actually_read; gchar* shell_out = (gchar*)g_malloc0(512); GIOStatus status = g_io_channel_read_chars(channel,shell_out, 512,&actually_read,NULL ); if(status != G_IO_STATUS_NORMAL){ //dont remove […]

使用Glib向GSList添加自定义结构

我正在尝试使用函数g_slist_append(list,&structure)将结构添加到单链表中。 这似乎工作(它添加指针),但我似乎无法找到一种方法来查看链接列表时结构中的元素。 我的结构看起来像这样: struct customstruct { int var1; int var2; char *string_1; } 然后,我列出一个列表: GSList *list = NULL; 然后,我附加一个结构的实例,如下所示: struct customstruct list_entry; list_entry.var1 = 1; list_entry.var2 = 2; list_entry.string_1 = “String”; list = g_slist_append(list, &entry); printf(“Entry var1 = %d\n”, list->data->var1); 最后一行失败,因为无法找到var1 (请求成员不是结构或联合)。 我想我需要把它投到正确的类型,但我不知道如何。 任何人?

内存泄漏/ GLib问题

1: /* 2: * File: xyn-playlist.c 3: * Author: Andrei Ciobanu 4: * 5: * Created on June 4, 2010, 12:47 PM 6: */ 7: 8: #include 9: #include 10: #include 11: #include 12: #include 13: #include 14: 15: /** 16: * Returns a list all the file(paths) from a directory. 17: * Returns ‘NULL’ […]

glib2实际上是否通过ALWAYS-MALLOC泄漏内存?

这个问题与其他许多问题不重复,因为我确实使用了G_DEBUG=gc-friendly和G_SLICE=always-malloc这是源代码: #include int main (int argc, char *argv[]) { GHashTable *ht; ht=g_hash_table_new(g_str_hash,g_str_equal); g_hash_table_insert(ht,”foo”,”bar”); g_hash_table_destroy(ht); return 0; } 以下是valgrind在此代码上的输出: # G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind –leak-check=full –show-reachable=yes ./test_vg ==1880== Memcheck, a memory error detector ==1880== Copyright (C) 2002-2010, and GNU GPL’d, by Julian Seward et al. ==1880== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info ==1880== […]