gpt4 book ai didi

c - gcc 未定义对 dbus_* 的引用

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

有很多类似的问题,但不幸的是他们没有太大帮助。

我正在尝试从 this 构建程序发帖,报错:

$ gcc `pkg-config --libs --cflags dbus-1` hh.c -o hh
/tmp/ccMabXOg.o: In function `main':
hh.c:(.text+0x18): undefined reference to `dbus_error_init'
hh.c:(.text+0x29): undefined reference to `dbus_bus_get'
hh.c:(.text+0x39): undefined reference to `dbus_error_is_set'
hh.c:(.text+0x5f): undefined reference to `dbus_error_free'
hh.c:(.text+0x80): undefined reference to `dbus_bus_name_has_owner'
hh.c:(.text+0x8f): undefined reference to `dbus_error_is_set'
hh.c:(.text+0x9f): undefined reference to `dbus_error_free'
hh.c:(.text+0xfb): undefined reference to `dbus_bus_request_name'
hh.c:(.text+0x10a): undefined reference to `dbus_error_is_set'
hh.c:(.text+0x11a): undefined reference to `dbus_error_free'
collect2: error: ld returned 1 exit status

include <dbus/dbus.h> , 以及系统上存在的文件:

# find / -name "dbus.h" -type f
/usr/include/dbus-1.0/dbus/dbus.h

但是dbus_error_init例如存在于 dbus-errors.h 中文件:

# grep -r dbus_error_init /usr/include/dbus-1.0/dbus/
/usr/include/dbus-1.0/dbus/dbus-errors.h:void dbus_error_init (DBusError *error);

我不是 C 开发人员,对 gcc 不是很熟悉和链接器,所以任何提示/链接表示赞赏。

最佳答案

您的链接顺序是从后到前。而不是:

gcc `pkg-config --libs --cflags dbus-1` hh.c -o hh

做:

gcc hh.c -o hh `pkg-config --libs --cflags dbus-1`

或:

gcc hh.c `pkg-config --libs --cflags dbus-1` -o hh

在链接序列中,需要符号定义的文件必须在提供定义的文件之前。所以库在目标文件之后。如果不清楚这如何适用于您的命令行读取 this question和我的答案。

关于c - gcc 未定义对 dbus_* 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37133522/

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