[英]How to compile a BlueZ application for ARM-Linux (IMX6UL)?
我想從我的工作站(x86,linux)為 ARM 應用處理器交叉編譯一個應用程序。 現在,我已經完成了這些打擊:
1,對於PC,Ubuntu 16.04,它已經支持BlueZ,我現在可以在Ubuntu中使用Bluetoothctl\\hcitool\\hciattach。
2,對於ARM,Linux 4.1,它也支持BlueZ,我可以使用Bluetoothctl\\hcitool\\hciattachin ARM CHIP。
我的演示代碼來自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;
}
我在上面構建代碼
我成功地得到了一個二進制文件(X86 PC),我可以用它來驅動藍牙加密狗在 PC 上掃描我自己的手機。
還是這一步,一切都很好,但我想為 ARM 構建這段代碼,所以我更改了 gcc --->arm-linux-gnueabihf-gcc 我已經測試了這個工具鏈,用於“helloword”和“讀取 UART” ,使用這個工具鏈是沒有問題的。
但是當我這樣做時#arm-linux-gnueabihf-gcc-o simplescan simplescan.c -lbluetooth。 弄錯了。
它顯示 asm/xxx.h 沒有這樣的文件。 (xxx 在這里意味着這么多文件)。
我嘗試使用CMD“定位”來搜索這個asm/xxx.h文件,但是我的電腦中有很多同名的asm/xxx.h文件,我該如何選擇合適的? 我需要 ARM-Linux 源代碼來構建嗎?
我現在不知道,請幫助我,非常感謝!
感謝Parthiban 的回答!我將sysroot 設置為bsp,然后成功!
你應該確保BSP中存在Bluetooth.so,還有下面的頭文件! bluetooth.h cmtp.h hci_lib.h l2cap.h sco.h sdp_lib.h bnep.h hci.h hidp.h rfcomm。 sdp.h
請飛思卡爾或其他芯片供應商為您的 ARM 芯片獲取 yocto 工具鏈!
root@yjppc:/a_work# $CC -o simplescan simplescan.c --sysroot /opt/myir-imx-fb/4.1.15-2.0.1/sysroots/cortexa7hf-neon-poky-linux-gnueabi/ -lbluetooth root @yjppc:/a_work# ls 應用材料 simplescan simplescan.c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.