首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我在编译链接glib库时,有使用-l -L -l指定头文件位置和库的路径,链接就是不通过呢?

为什么我在编译链接glib库时,有使用-l -L -l指定头文件位置和库的路径,链接就是不通过呢?

提问于 2021-04-19 18:24:31
回答 0关注 0查看 377
#include <gio/gio.h>
#include <libnm/nm-dbus-interface.h>

int main()
{

	GDBusProxy *proxy = NULL;
    gboolean found = FALSE;

	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                   G_DBUS_PROXY_FLAGS_NONE,
                   NULL,
                   // "org.freedesktop.NetworkManager"
                   NM_DBUS_SERVICE,
                   //"/org/freedesktop/NetworkManager"
                   NM_DBUS_PATH,
                   //"org.freedesktop.NetworkManager"
                   //NM_DBUS_INTERFACE,
                   "org.freedesktop.DBus.Properties",
                   NULL, NULL);
	g_assert (proxy != NULL);

	g_object_unref (proxy);
	return 0;
}
wrx@ubuntu:~/Desktop$ gcc a.c -o a.out -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ 
-L/usr/lib/x86_64-linux-gnu -lglib-2.0
/tmp/ccSOt4vE.o: In function `main':
a.c:(.text+0x3c): undefined reference to `g_dbus_proxy_new_for_bus_sync'
a.c:(.text+0x76): undefined reference to `g_object_unref'
collect2: error: ld returned 1 exit status


wrx@ubuntu:~/Desktop$ gcc a.c -o a.out $(pkg-config --cflags --libs glib-2.0)
/tmp/ccOphBNT.o: In function `main':
a.c:(.text+0x3c): undefined reference to `g_dbus_proxy_new_for_bus_sync'
a.c:(.text+0x76): undefined reference to `g_object_unref'
collect2: error: ld returned 1 exit status


可问题是glib库明明就在路径下找得到。。。。
wrx@ubuntu:~$ ls /usr/lib/x86_64-linux-gnu/libglib*
/usr/lib/x86_64-linux-gnu/libglib-2.0.a
/usr/lib/x86_64-linux-gnu/libglib-2.0.so
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
/usr/lib/x86_64-linux-gnu/libglibmm-2.4.so.1
/usr/lib/x86_64-linux-gnu/libglibmm-2.4.so.1.3.0
/usr/lib/x86_64-linux-gnu/libglibmm_generate_extra_defs-2.4.so.1
/usr/lib/x86_64-linux-gnu/libglibmm_generate_extra_defs-2.4.so.1.3.0
/usr/lib/x86_64-linux-gnu/libglib.so

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档