蓝牙C程序找不到库-lbluetooth
我使用本教程学习如何在我的raspberry pi上使用c语言中的蓝牙: 我当前正在尝试运行simplescan.c:蓝牙C程序找不到库-lbluetooth,c,bluetooth,raspberry-pi,raspberry-pi3,bluez,C,Bluetooth,Raspberry Pi,Raspberry Pi3,Bluez,我使用本教程学习如何在我的raspberry pi上使用c语言中的蓝牙: 我当前正在尝试运行simplescan.c: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/socket.h> #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include &
#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>
int main(int argc, char **argv)
{
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };
dev_id = hci_get_route(NULL);
sock = hci_open_dev( dev_id );
if (dev_id < 0 || sock < 0) {
perror("opening socket");
exit(1);
}
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
if( num_rsp < 0 ) perror("hci_inquiry");
for (i = 0; i < num_rsp; i++) {
ba2str(&(ii+i)->bdaddr, addr);
memset(name, 0, sizeof(name));
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
name, 0) < 0)
strcpy(name, "[unknown]");
printf("%s %s\n", addr, name);
}
free( ii );
close( sock );
return 0;
}
我得到这个错误:
/usr/bin/ld: cannot find -lbluetooth
collect2: error: ld returned 1 exit status
编辑:由于某种原因,现在当我尝试编译时,错误已更改为:
simplescan.c:5:10: fatal error: bluetooth/bluetooth.h: No such file or directory
#include <bluetooth/bluetooth.h>
simplescan.c:5:10:致命错误:bluetooth/bluetooth.h:没有这样的文件或目录
#包括
我读到BlueZ预装在Raspbian上,我有最新版本,但我似乎找不到bluetooth库文件夹或其中的任何.h文件
本教程可能很旧,因此内容可能会有所改变。
bluetooth库是否与bluez一起预装?如果是,我应该在哪里确认
如果这个库不在我的RPI上,我应该从哪里获得它?那个教程已经过时了,因为BlueZ从那时起就已经离开了。早在2012年就有 2017年,来自Bluez 现在使用的API是mgmt API,其重点是系统级功能,并记录在: 对于应用程序级,您应该使用D-Bus API。这些文件分布在以下文件中: C示例并不多。源代码树中的示例适用于D-Bus API,并且都使用Python:
查看
bluetoothctl
工具的代码可能会为您提供更好的示例。此代码可在以下位置获得:该教程已过时,因为BlueZ已从那时起继续。早在2012年就有
2017年,来自Bluez
现在使用的API是mgmt API,其重点是系统级功能,并记录在:
对于应用程序级,您应该使用D-Bus API。这些文件分布在以下文件中:
C示例并不多。源代码树中的示例适用于D-Bus API,并且都使用Python:
查看
bluetoothctl
工具的代码可能会为您提供更好的示例。此代码位于:这将非常困难,似乎没有任何代码有任何注释。这将非常困难,似乎没有任何代码有任何注释。
simplescan.c:5:10: fatal error: bluetooth/bluetooth.h: No such file or directory
#include <bluetooth/bluetooth.h>