gpt4 book ai didi

c - 在 C 程序中使用 glib 库

转载 作者:可可西里 更新时间:2023-11-01 11:44:15 25 4
gpt4 key购买 nike

我想在我的 C 程序中使用哈希表。

我代码:

...
#include <glib.h>

void main(int argc, char **argv)
{
GHashTable *g_hash_table;
...
g_hash_table = g_hash_table_new(g_int_hash, g_int_equal);
...
}

然后我编译:

$ gcc -I/usr/include/glib-2.0
-I/usr/lib/i386-linux-gnu/glib-2.0/include
-lglib-2.0 -o test test.c

或相同的命令:

$ gcc `pkg-config --cflags --libs glib-2.0` -o test test.c

但无论如何结果是:

test.c: underfined reference to `g_int_equal`
test.c: underfined reference to `g_int_hash`
test.c: underfined reference to `g_hash_table_new`
collect2: ld returned 1 exit status

为什么我不能编译我的程序?我错误地包含了 glib 库?

最佳答案

您需要在命令行中使用它们的源文件和目标文件之后指定库:

gcc test.c `pkg-config --cflags --libs glib-2.0` -o test 

关于c - 在 C 程序中使用 glib 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11466904/

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