【问题标题】:How to compile a BlueZ application for ARM-Linux (IMX6UL)?如何为 ARM-Linux (IMX6UL) 编译 BlueZ 应用程序?
【发布时间】:2020-03-20 07:06:26
【问题描述】:

我想从我的工作站(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;
}

我在上面构建代码

gcc -o simplescan simplescan.c -lbluetooth

成功了 我有一个二进制文件(X86 PC),我可以用它来驱动蓝牙加密狗在电脑上扫描我自己的手机。

还是这一步,一切都很好,但我想为 ARM 构建这段代码, 所以我改变了 gcc --->arm-linux-gnueabihf-gcc 我已经测试过这个工具链,对于“helloword”和“read UART”,使用这个工具链没问题。

但是当我这样做时 #arm-linux-gnueabihf-gcc-o simplescan simplescan.c -lbluetooth。搞错了。

它显示 asm/xxx.h 没有这样的文件。 (这里的 xxx 表示很多文件)。

我尝试使用CMD“定位”来搜索这个asm/xxx.h文件,但是我的电脑中有这么多同名的asm/xxx.h文件,我该如何选择一个合适的?我需要构建 ARM-Linux 源代码吗?

我现在不知道,请帮帮我,非常感谢!

【问题讨论】:

  • 你可以用arm-linux-gnueabihf-gcc --sysroot=&lt;/path/to/arm/sysroot/ -o ./bin/simple ./simple.c -lbluetooth编译。这里的 sysroot 路径应该包含 bluez 相关的库、includes 和 libc + 系统库。您也可以使用 DBUS API,详见此处:linumiz.com/…
  • 非常感谢yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy!!!!我用imx6ul的BSP,设置sysroot为BSP,然后编译成功!

标签: c linux arm embedded-linux bluez


【解决方案1】:

感谢帕蒂班的回答! 我把sysroot设置为bsp,然后成功!

你应该确保蓝牙.so存在于BSP中,下面的头文件也存在! bluetooth.h cmtp.h hci_lib.h l2cap.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 /opt/myir-imx-fb/4.1.15-2.0.1/sysroots/cortexa7hf-neon-poky-linux-gnueabi/ -l蓝牙 root@yjppc:/a_work# ls 应用程序材料 simplescan simplescan.c

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多