簡體   English   中英

C ++ Bluez Eclipse鏈接器配置

[英]c++ bluez eclipse linker config

我試圖將bluez庫添加到樹莓派3(樹莓派)上的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, ...

  1. 在日食:

項目>屬性> C / C ++構建>設置> GCC C ++編譯器>包含

在包含路徑(-l)中,我添加:/usr/local/include/bluez-5.37/lib/bluetooth

  1. 月食

項目>屬性> C / C ++構建>設置> GCC C ++鏈接器>庫

在庫(-l)中,我添加:藍牙

在庫搜索路徑(-L)中,我添加:/ usr / local / lib

這是我正在嘗試構建的代碼

#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)

在這件事上有點新手...請幫助嗎? 謝謝!

嘗試安裝libbluetooth-dev ,這比較容易,特別是對於初學者。 這樣,您將只需要-lbluetooth標志。 您唯一需要更改的是標頭包含,您需要在最后三個包含添加bluetooth/ 帶標題的bluetooth文件夾的父文件夾很可能已經在您的庫搜索路徑中,因此您不應將其添加到搜索路徑中,而應訪問諸如#include <bluetooth/bluetooth.h>類的標題文件。

我執行了與@Drazz相同的步驟。 注意,我在Windows上使用了eclipse並在Raspberry Pi上驗證了代碼,因此我使用了SysProgs的交叉編譯工具鏈

這些步驟是:

1-我從bluez下載了最新的bluez版本5.43

2-我按照Adafruit中提到的步驟在pi上編譯了下載的文件

3-我將已編譯的文件夾“ bluez-5.43”從我的Pi復制到了PC,以便與Eclipse一起使用。 我正在使用Sysgcc交叉編譯工具鏈進行開發在Windows上使用SyssGcc工具鏈進行交叉編譯

4-我在SyssGcc工具鏈上安裝Eclipse后,使用在Eclipse中設置交叉編譯中的步驟進行了准備

5-我創建了一個c ++項目,並復制了第一個URL中提到的藍牙的主要代碼,然后轉到:

項目>屬性> C / C ++構建>設置> GCC C ++編譯器>包含

在包含路徑(-l)中,我添加:“ [[從pi復制復制的庫的路徑] \\ bluez-5.43 \\ lib”

在鏈接部分:

在Eclipse項目>屬性> C / C ++構建>設置> GCC C ++鏈接器>庫中

在庫(-l)中,我添加:藍牙內部

在庫搜索路徑(-L)中,我添加:“ [[從pi復制復制的庫的路徑] \\ bluez-5.43 \\ lib.libs”

在Pi上編譯並運行最終的可執行文件。打開手機的藍牙使其可見。 您會發現Pi可以在屏幕上讀取您的手機。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM