我正在使用 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放在scannbd.c后面,如下:
例如: gcc scanbd.c -lbluetooth -o scanbd
关于c++ - 在 RaspberryPi 上使用 gcc 编译蓝牙问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24478767/