本文介绍了编译错误dbus-ping-pong的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从

我正在尝试使用以下命令对其进行编译

I am trying to compile it using the command

gcc pkg-config --libs --cflags dbus-1 dbus-glib-1-2 glib-2.0 -o dbus-ping-pong dbus-ping-pong.c

但是我收到以下链接器错误

But i am getting the below linker errors

/tmp/ccmJkxXb.o: In function g_once_init_enter': dbus-ping-pong.c:(.text+0x22): undefined reference tog_once_init_enter_impl'
/tmp/ccmJkxXb.o: In function dbus_glib_marshal_echo_srv__BOOLEAN__STRING_POINTER_POINTER': dbus-ping-pong.c:(.text+0x52): undefined reference tog_return_if_fail_warning'
dbus-ping-pong.c:(.text+0x79): undefined reference to g_return_if_fail_warning' dbus-ping-pong.c:(.text+0x9d): undefined reference tog_value_peek_pointer' dbus-ping-pong.c:(.text+0xac): undefined reference to g_value_peek_pointer' dbus-ping-pong.c:(.text+0x109): undefined reference tog_value_set_boolean' /tmp/ccmJkxXb.o: In function echo_ping_class_intern_init': dbus-ping-pong.c:(.text+0x122): undefined reference tog_type_class_peek_parent' /tmp/ccmJkxXb.o: In function echo_ping_get_type': dbus-ping-pong.c:(.text+0x162): undefined reference tog_intern_static_string' dbus-ping-pong.c:(.text+0x192): undefined reference to g_type_register_static_simple' dbus-ping-pong.c:(.text+0x1a8): undefined reference tog_once_init_leave' /tmp/ccmJkxXb.o: In function echo_ping_class_init': dbus-ping-pong.c:(.text+0x1cd): undefined reference tog_type_class_add_private' dbus-ping-pong.c:(.text+0x1e2): undefined reference to dbus_g_object_type_install_info' /tmp/ccmJkxXb.o: In functionecho_ping_init': dbus-ping-pong.c:(.text+0x1fe): undefined reference to g_type_instance_get_private' /tmp/ccmJkxXb.o: In functionecho_ping': dbus-ping-pong.c:(.text+0x21d): undefined reference to g_strdup' /tmp/ccmJkxXb.o: In functionclient': dbus-ping-pong.c:(.text+0x265): undefined reference to dbus_g_proxy_new_for_name' dbus-ping-pong.c:(.text+0x2c3): undefined reference todbus_g_proxy_call' dbus-ping-pong.c:(.text+0x2d1): undefined reference to dbus_g_error_quark' dbus-ping-pong.c:(.text+0x2f1): undefined reference todbus_g_error_get_name' dbus-ping-pong.c:(.text+0x305): undefined reference to g_printerr' dbus-ping-pong.c:(.text+0x31d): undefined reference tog_printerr' dbus-ping-pong.c:(.text+0x328): undefined reference to g_error_free' dbus-ping-pong.c:(.text+0x358): undefined reference tog_print' dbus-ping-pong.c:(.text+0x363): undefined reference to g_free' /tmp/ccmJkxXb.o: In functionmain': dbus-ping-pong.c:(.text+0x38f): undefined reference to g_type_init' dbus-ping-pong.c:(.text+0x3a3): undefined reference todbus_g_bus_get' dbus-ping-pong.c:(.text+0x3c7): undefined reference to g_object_new' dbus-ping-pong.c:(.text+0x3df): undefined reference tog_type_check_instance_cast' dbus-ping-pong.c:(.text+0x3f9): undefined reference to dbus_g_connection_register_g_object' dbus-ping-pong.c:(.text+0x406): undefined reference todbus_g_connection_get_connection' dbus-ping-pong.c:(.text+0x426): undefined reference to dbus_bus_request_name' dbus-ping-pong.c:(.text+0x43a): undefined reference tog_main_loop_new' dbus-ping-pong.c:(.text+0x44a): undefined reference to `g_main_loop_run'

有人可以帮助我解决此问题吗?

Can anyone plz help me to resolve this issue ?

推荐答案

gcc- o dbus-ping-pong dbus-ping-pong.c pkg-config --libs --cflags dbus-1 dbus-glib-1 glib-2.0

gcc -o dbus-ping-pong dbus-ping-pong.c pkg-config --libs --cflags dbus-1 dbus-glib-1 glib-2.0

以下注释可以最好地说明问题(从某些论坛复制)

The following comment best explains the problem(Copied from some forum)

以正确的顺序列出库非常重要。当gcc扫描命令行时,它会提取到目前为止所需的内容。每次看到对象时,都会将其添加到程序中。每次看到库时,它只会拉入此时所需的对象。您应该始终在对象之后列出库。

"It's very important to list libraries in the correct order. As gcc scans the command line, it pulls in what it needs so far. Each time it sees an object, it adds it to the program. Each time it sees a library, it pulls in only the objects that it needs at that point. You should always list libraries after the objects"

pkg-config程序用于检索有关系统中已安装库的信息。它通常用于编译和链接一个或多个库。

The pkg-config program is used to retrieve information about installed libraries in the system. It is typically used to compile and link against one or more libraries.

如果仅给出pkg-config --libs --cflags dbus-1 dbus-glib-1 glib-2.0不带任何单引号或双引号在命令行上它扩展为
-pthread -I / usr / include / dbus-1.0 -I / usr / lib / i386-linux-gnu / dbus-1.0 / include -I / usr / include / glib-2.0 -I / usr / lib / i386-linux-gnu / glib-2.0 / include -pthread -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lgthread-2.0 -lrt -lglib-2.0
因此它具有目标文件后提到的所有include和Dependenci库

If you give only pkg-config --libs --cflags dbus-1 dbus-glib-1 glib-2.0 without any single or double quotes on command line it expands to-pthread -I/usr/include/dbus-1.0 -I/usr/lib/i386-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include  -pthread -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lgthread-2.0 -lrt -lglib-2.0so it has all the includes and dependenci libs mentioned after object file

这篇关于编译错误dbus-ping-pong的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 09:55