使用dbus时,编译出错:
# gcc dbus-send_test.c
/tmp/ccFTOCOc.o: In function `main':
dbus-send_test.c:(.text+0x1a): undefined reference to `g_main_loop_new'
dbus-send_test.c:(.text+0x2a): undefined reference to `dbus_error_init'
dbus-send_test.c:(.text+0x3b): undefined reference to `dbus_bus_get'
dbus-send_test.c:(.text+0x66): undefined reference to `g_log'
dbus-send_test.c:(.text+0x72): undefined reference to `dbus_error_free'
dbus-send_test.c:(.text+0x8e): undefined reference to `dbus_connection_setup_with_g_main'
dbus-send_test.c:(.text+0xa6): undefined reference to `g_main_loop_run'
上网查得,需要链接到库文件dbus-1:
# gcc dbus-send_test.c -ldbus-1
/tmp/ccnL42UW.o: In function `main':
dbus-send_test.c:(.text+0x1a): undefined reference to `g_main_loop_new'
dbus-send_test.c:(.text+0x66): undefined reference to `g_log'
dbus-send_test.c:(.text+0x8e): undefined reference to `dbus_connection_setup_with_g_main'
dbus-send_test.c:(.text+0xa6): undefined reference to `g_main_loop_run'
/tmp/ccnL42UW.o: In function `send_ping':
dbus-send_test.c:(.text+0x11f): undefined reference to `g_print'
collect2: ld returned 1 exit status
又加了一个库文件:glib-2.0
# gcc `pkg-config --cflags dbus-1` \
> `pkg-config --cflags glib-2.0` \
> dbus-send_test.c \
> `pkg-config --libs dbus-1` \
> `pkg-config --libs glib-2.0`
/tmp/cczSd10k.o: In function `main':
dbus-send_test.c:(.text+0x8e): undefined reference to `dbus_connection_setup_with_g_main'
collect2: ld returned 1 exit status
又加一个库dbus-glib-1后编译通过。
但是查看dbus-glib-1的库:
# pkg-config --libs dbus-glib-1
-L/lib64 -ldbus-glib-1 -ldbus-1 -lpthread -lrt -lgobject-2.0 -lglib-2.0
所以:
# gcc dbus-send_test.c -ldbus-glib-1
此链接已经包含-ldbus-1、-lglib-2.0
编译通过了
阅读(5825) | 评论(0) | 转发(0) |