我想从我的工作站(x86,linux)为ARM应用程序处理器交叉编译一个应用程序。现在,我已经把这些作为打击完成了:
1,对于PC,Ubuntu16.04,它已经支持BlueZ了,我现在可以在Ubuntu中使用Bluetoothctl\hcitool\hciattach。
2,对于ARM,Linux4.1,它也支持BlueZ,我可以使用蓝牙can \hcitool\hciattachin芯片。
我的演示代码来自https://people.csail.mit.edu/albert/bluez-intro/c404.html
下面代码的功能是扫描蓝牙设备。
#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;
}我在上面构建代码
gcc -o simplescan simplescan.c -lbluetooth
这是成功的,我有一个二进制(X86 PC),我可以用它来驱动蓝牙软盘,以扫描我自己的手机在个人电脑。
这一步,一切都很好,但是我想为ARM构建这个代码,所以我改变了gcc -->arm-linux-gnueabihf-gcc-我已经测试了这个工具链,为了一个"helloword“和‘阅读UART',使用这个工具链是没有问题的。
,但是当我这么做的时候#arm gnueabihf-gcc-oSimpleScansimplescan.c -lbluetooth。弄错了。
它显示asm/xxx.h没有这样的文件。(这里的xxx指的是这么多文件)。
我尝试使用CMD "locate“搜索这个asm/xxx.h文件,但是我的PC中有这么多同名的asm/xxx.h文件,我如何选择合适的文件呢?我需要ARM-Linux源代码来构建吗?
我现在不知道了,请帮帮我,非常感谢!
发布于 2019-12-03 02:17:26
谢谢帕蒂班的回答!我将sysroot设置为bsp,然后成功!
您应该确保BSP中存在Bluetooth.so,下面的头文件也是存在的!H hci_lib.h 12 cap.h sco.h sdp_lib.h bnep.h hci.h hidp.h rfcomm.h sdp.h
请飞思卡尔或其他芯片供应商为您的ARM芯片获得yocto工具链!
root@yjppc:/a_work# $CC -o simplescan simplescan.c -sysroot$CC -lbluetooth root@yjppc:/a_work# ls应用程序材料simplescan simplescan.c
https://stackoverflow.com/questions/59024231
复制相似问题