首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >蓝牙C程序找不到库-lbluetooth

蓝牙C程序找不到库-lbluetooth
EN

Stack Overflow用户
提问于 2020-10-08 02:50:11
回答 1查看 288关注 0票数 0

我使用本教程学习如何在raspberry pi:https://people.csail.mit.edu/albert/bluez-intro/c404.html上使用c中的蓝牙。

我目前正在尝试运行simplescan.c:

代码语言:javascript
复制
#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;
}

当我使用以下命令编译时:

代码语言:javascript
复制
gcc -o simplescan simplescan.c -lbluetooth

我知道这个错误:

代码语言:javascript
复制
/usr/bin/ld: cannot find -lbluetooth
collect2: error: ld returned 1 exit status

编辑:由于某些原因,当我试图编译时,错误已更改为:

代码语言:javascript
复制
simplescan.c:5:10: fatal error: bluetooth/bluetooth.h: No such file or directory
 #include <bluetooth/bluetooth.h>

我已经读到BlueZ是预装在Raspbian上的,我有最新的版本,但我似乎找不到蓝牙库文件夹或其中的任何.h文件。

本教程可能已经过时了,所以事情可能已经发生了变化。蓝牙库是和bluez一起预装的吗?如果是的话,我应该在哪里确认呢?

如果这个库不在我的RPI上,我应该从哪里得到它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-08 10:15:00

该教程已经过时,因为BlueZ从那时起就一直在前进。早在2012年,就有主要发展项目将转向新的API

然后在2017年,来自布吕兹的不建议使用8种工具

现在要使用的API是mgmt,它专注于系统级的功能,并记录在:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/mgmt-api.txt中。

对于应用程序级别,您应该使用的是D总线API。这些文档分布在:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc中的许多文档中。

这里的C例子不多。源代码树中的示例用于D-Bus API,并且全部使用Python:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test

查看bluetoothctl工具的代码可能会给您提供更好的示例。此代码可在以下站点获得:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/client

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64255087

复制
相关文章

相似问题

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