首页 > 解决方案 > 如何为 GCC 链接 Libbluetooth?

问题描述

我正在尝试在我的 c 文件中使用 hci.h、hci_lib.h 等。将目标文件链接到 exec 的最终命令如下所示:

gcc -g3 -o execfile ./dev1.o ./dev2.o ./main.o ./nets.o `pkg-config --cflags --libs glib-2.0 gio-unix-2.0`

但是我收到这样的链接错误:

undefined reference to `hci_open_dev'
undefined reference to `hci_le_set_scan_parameters'
undefined reference to `hci_le_set_scan_enable'
undefined reference to `hci_le_set_scan_enable'
undefined reference to `hci_close_dev'

我知道这是因为我没有将 -lbluetooth 指定给 gcc。

有没有办法像我为上面的 glib 和 gio-unix 那样指定 libbluetooth-dev 到 pkg-config ?

标签: gcclinker

解决方案


推荐阅读