【问题标题】:Bluetooth issues compiling with gcc on RaspberryPi在 RaspberryPi 上使用 gcc 编译的蓝牙问题
【发布时间】:2014-06-29 18:02:10
【问题描述】:

我正在使用 Raspbian (Debian Wheezy)。我已经安装了

$ sudo apt-get install bluez bluez-tools bluez-dbg bluez-hcidump bluez-tools python-bluez libbluetooth-dev libbluetooth3 libbluetooth3-dbg

但在尝试编译以下行时,它说它不知道该库:

$ gcc scanbd.c -o scanbd
/tmp/ccl5BrFc.o: In function `main':
scanbd.c:(.text+0x84): undefined reference to `hci_get_route'
scanbd.c:(.text+0x90): undefined reference to `hci_open_dev'
scanbd.c:(.text+0x11c): undefined reference to `hci_inquiry'
scanbd.c:(.text+0x170): undefined reference to `ba2str'
scanbd.c:(.text+0x1c8): undefined reference to `hci_read_remote_name'
collect2: ld returned 1 exit status

这些是我在 .c 文件中的包含语句:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>

有谁知道我做错了什么? 谢谢

更新:事实证明,我做了所有正确的事情,但我不得不关闭/拔下 RPi,然后重新启动以使一切正常工作...... -lbluetooth 在那之后的路径中。 谢谢大家

【问题讨论】:

  • 仅安装蓝牙库是不够的,您还需要将它们链接到您的程序。将-lbluetooth 添加到您的编译器命令中,未定义的引用错误将消失。
  • 对不起,我使用“# gcc -o scanbd scanbd.c -lbluetooth”行编译。它说没有这样的文件或目录“蓝牙”。蓝牙库文件的文件扩展名是什么?也许我可以搜索并查看它是否已安装。或者也许它不在路径中?虽然我确实添加了 /usr/include 和 /usr/library 路径。从编译器命令中删除 -lbluetooth 库时出现 hci_* 错误。正如我所提到的,当我重新添加 -lbluetooth 时,它说它不知道。
  • 当您将-lbluetooth 附加到您的 gcc 命令时,您能否编辑您的问题并添加输出? gcc -o scanbd scanbd.c -lbluetooth(那是 DASH ELL BEE ELL EWE EEE...等)

标签: c++ c gcc bluetooth raspbian


【解决方案1】:

希望下面的链接可以帮助你。

Linking with libbluetooth.so

编译时请在scannbd.c后面加上参数-lbluetooth如下:

例如: gcc scanbd.c -lbluetooth -o scanbd

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    相关资源
    最近更新 更多