簡體   English   中英

如何編譯blacklib(c ++)

[英]how to compile blacklib (c++)

我正在運行一個beaglebone,並想編寫一個程序來對ADC進行采樣。 我試圖從這里使用blacklib( http://blacklib.yigityuce.com/index.html )。 我克隆了git: https//github.com/yigityuce/BlackLib

並嘗試用。編譯示例

g++ exampleAndTiming.cpp -std=c++11

然而,這給了我很多這樣的錯誤:

In file included from exampleAndTiming.cpp:33:0:
exampleAndTiming/exampleAndTiming_GPIO.h: In function 'void exampleAndTiming_GPIO()':
exampleAndTiming/exampleAndTiming_GPIO.h:97:12: error: 'sleep' was not declared in this scope
     sleep(1);
            ^
In file included from exampleAndTiming.cpp:34:0:
exampleAndTiming/exampleAndTiming_ADC.h: In function 'void exampleAndTiming_ADC()':
exampleAndTiming/exampleAndTiming_ADC.h:67:16: error: 'usleep' was not declared in this scope
     usleep(1000);
                ^

所以我包括unistd.h(在exampleAndTiming.cpp中),但后來我得到這樣的錯誤:

/tmp/ccbgiXE9.o: In function `exampleAndTiming_GPIO()':
exampleAndTiming.cpp:(.text+0x50): undefined reference to `Timing::startMeasure(std::string)'
exampleAndTiming.cpp:(.text+0x80): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0xbc): undefined reference to `Timing::endMeasure(std::string)'
exampleAndTiming.cpp:(.text+0xec): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x104): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x11c): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x158): undefined reference to `Timing::startMeasure(std::string)'

我一直在查看一些庫示例並編譯它,但我無法理解這一切。 我以前編譯了大量的c ++和c程序,但我無法使用這個程序。 所以任何幫助將不勝感激。

完整指南如何在運行ANGSTROM的BEAGLEBONE BLACK(rev C)上直接編譯BLACKLIB:

程式:

Putty - 從Windows與BBB通信(使用SSH和USB線)

WinSCP - 直接在BBB上管理(上傳,創建,刪除)文件

Code :: Blocks - 編寫C ++程序

可選

白蟻2.9 - 從UART發送和接收UART傳輸< - > USB轉換器(實際上Putty也可以用來做)

1)官方網站獲取BlackLib

2)解壓縮庫並將以下文件復制到單獨的文件夾中:

BlackADC.cpp, BlackADC.h, BlackCore.cpp, BlackCore.h, BlackDef.h, BlackErr.h, BlackGPIO.cpp, BlackGPIO.h, BlackI2C.cpp, BlackI2C.h, BlackLib.h, BlackPWM.cpp, BlackPWM.h, BlackSPI.cpp, BlackSPI.h, BlackUART.cpp, BlackUART.h

3)在Code :: Blocks BlackUART.cpp, BlackSPI.cpp, BlackI2C.cpp打開以下文件並添加

#include <unistd.h>

#include "BlackUART.h" ,“unistd.h”包括所有函數,如sleep(),open(),close(),......否則似乎缺失

4)創建自己的程序main.cpp ,可以使用以下代碼測試UART1和UART2:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sstream>
#include <string>
#include <iostream>


#include "BlackLib.h"


int main(){

    std::string writeToUart1;
    std::string writeToUart2;
    std::string readFromUart1;
    std::string readFromUart2;
    int counter;
    std::ostringstream os1;
    std::ostringstream os2;

    BlackLib::BlackUART  Uart1(BlackLib::UART1,
                               BlackLib::Baud9600,
                               BlackLib::ParityEven,
                               BlackLib::StopOne,
                               BlackLib::Char8 );
    // Pins on BeagleBone Black REV C
    // UART1_RX -> GPIO_15 (P9.24)
    // UART1_RX -> GPIO_14 (P9.26)

    BlackLib::BlackUART  Uart2(BlackLib::UART2,
                               BlackLib::Baud9600,
                               BlackLib::ParityEven,
                               BlackLib::StopOne,
                               BlackLib::Char8 );
    // Pins on BeagleBone Black REV C
    // UART2_RX -> GPIO_2 (P9.22)
    // UART2_RX -> GPIO_3 (P9.21)

    std::cout << "Program UART start" << std::endl << std::flush;

    Uart1.open( BlackLib::ReadWrite | BlackLib::NonBlock );
    Uart2.open( BlackLib::ReadWrite | BlackLib::NonBlock );

    counter = 0;

    while (true){

        os1.str("");
        os1.clear();
        os1 << "Uart1 to TX: " << counter << "\n";
        writeToUart1 = os1.str();
        Uart1 << writeToUart1;

        readFromUart1 = "";
        Uart1 >> readFromUart1;
        if (readFromUart1.compare("") != 0){
                std::cout << "Uart1 from RX: " << readFromUart1 << "\n" << std::flush;
        }
        Uart1.flush( BlackLib::bothDirection );
        counter++;
        sleep(2);


        os2.str("");
        os2.clear();
        os2 << "Uart2 to TX: " << counter << "\n";
        writeToUart2 = os2.str();
        Uart2 << writeToUart2;

        readFromUart2 = "";
        Uart2 >> readFromUart2;
        if (readFromUart2.compare("") != 0){
                std::cout << "Uart2 from RX: " << readFromUart2 << "\n" << std::flush;
        }
        Uart2.flush( BlackLib::bothDirection );
        counter++;
        sleep(2);


    }

    return 1;
}

5)將main.cpp保存到與BlackLib文件相同的文件夾中

6)使用WinSCP,在BBB上創建目錄(例如/ home / uart)並將所有BlackLib文件和main.cpp復制到此文件夾中

7)打開Putty並通過以下方式導航到該文件夾​​: cd /home/uart

8)使用以下命令編譯文件: gcc *.cpp -o main -std=c++11

9)運行程序: ./main

10)將導線連接到UART < - > USB轉換器和BBB。 BBB的輸出應該如下:

Uart2 to TX: 1   OR   Uart1 to TX: 0
Uart2 to TX: 3   OR   Uart1 to TX: 2

取決於電線的連接

似乎我自己設法修復它,一些不包括所有cpp文件的nooblike行為,但更重要的是,我還需要將#include添加到BlackCore.h以避免大量未定義的函數錯誤。

最終命令:

g++ exampleAndTiming.cpp exampleAndTiming/Timing.cpp BlackADC.cpp BlackCore.cpp BlackGPIO.cpp BlackI2C.cpp BlackPWM.cpp BlackSPI.cpp BlackUART.cpp -std=c++11

我可能需要制作一個makefile來單獨編譯庫,有時間做一些挖掘和學習。

我是BlackLib的創作者,YiğitYÜCE。 你自己找到了答案。 您在評論中提到的makefile將很快發布。

暫無
暫無

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

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