2016-06-22 49 views
0

我想添加bluez库到我的eclipse项目上覆盆子pi 3(raspbian)。这是我做了什么:C++ bluez eclipse连接器配置

  1. 配合bluez上已经安装了树莓派3,但我没有找到头文件,所以我也跟着这个教程:目录

https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation

现在/usr/local/include/bluez-5.37/lib/bluetooth我有bluetooth.h,hci.h, ...

  • 基于Eclipse:
  • 项目>属性> C/C++编译>设置> GCC C++编译器>含

    在包括路径(-1)我添加:/usr/local/include/bluez-5.37/lib/bluetooth

  • 基于Eclipse
  • 项目>属性> C/C++编译>设置> GCC C++链接>库

    在库(-1)我添加蓝牙

    在库搜索路径(-L)我补充一下:在/ usr/local/lib目录

    这是代码,我是trying to build

    #include <stdio.h> 
    #include <stdlib.h> 
    #include <unistd.h> 
    #include <sys/socket.h> 
    #include <bluetooth.h> 
    #include <hci.h> 
    #include <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; 
    } 
    

    标题找到,但这是控制台说:

    02:25:09 **** Incremental Build of configuration Release for project ComputerVision **** 
    make all 
    Building target: ComputerVision 
    Invoking: GCC C++ Linker 
    g++ -L/usr/local/lib -o "ComputerVision" ./src/ComputerVision.o -lopencv_core -lbluetooth -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann 
    /usr/bin/ld: cannot find -lbluetooth 
    makefile:45: recipe for target 'ComputerVision' failed 
    collect2: error: ld returned 1 exit status 
    make: *** [ComputerVision] Error 1 
    
    02:25:09 Build Finished (took 382ms) 
    

    位新手,对这个事情...任何帮助PLZ?谢谢!

    回答

    0

    尝试安装libbluetooth-dev,这很容易,尤其是对于初学者。这样你只需要-lbluetooth标志。您需要更改的唯一一件事是您的标题包含,您需要将bluetooth/添加到最后三个包含。带有标题的蓝牙文件夹的父文件夹很可能已经存在于您的图书馆搜索路径中,因此您不应该将其添加到搜索路径,而是访问像#include <bluetooth/bluetooth.h>这样的头文件。

    +0

    对不起。这很有用。谢谢 – Drazz

    0

    我完成了您提及的@Drazz相同的步骤。 请注意,我在Windows上使用Eclipse和验证了我的树莓派的代码,因为这个原因,我用交叉编译工具链从SysProgs

    的步骤是:

    1 - 我下载了最新版本的bluez 5。43从bluez

    2-予编译所下载的文件在我的PI以下在Adafruit

    3-提到的步骤我复制已编译的文件夹“的bluez-5.43”从我裨到PC与蚀使用它。我使用Sysgcc交叉编译工具链Cross Compiling on windows using SyssGcc toolchain

    4-予制备的蚀上Setting Up Cross-Compilation In Eclipse

    5-安装使用的步骤的SyssGcc工具链后我创建一个C++项目和复制中提到的蓝牙主代码显影第一个网址,去:

    项目>属性> C/C++编译>设置> GCC C++编译器>包括

    在include路径(-l)我补充说:“[路径复制了编译库从pi] \ bluez-5.43 \ lib“

    在链接部分:

    在Eclipse项目>属性> C/C++编译>设置> GCC C++链接>库

    在库(-1)我添加:蓝牙内部

    在库搜索路径(-L)中我添加:“[您从pi复制编译库的路径] \ bluez-5.43 \ lib.libs”

    编译并运行Pi上的最终可执行文件。您的手机蓝牙,并使其可见。你会发现Pi可以在屏幕上阅读你的手机。