如何编译blacklib(C ++)(how to compile blacklib (c++))

2019-09-29 16:22发布

我运行一个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程序,但我不能让这一个工作。 因此,任何帮助将不胜感激。

Answer 1:

完全指南如何编译BLACKLIB直接BEAGLEBONE BLACK(C版本)运行埃:

程式:

腻子 -从Windows与BBB通讯(使用USB电缆SSH)

WinSCP赋予 -管理(上传,创建,删除)文件直接在BBB

代码::块 -写C ++程序

可选

白蚁2.9 -发送和从UART接收UART发送< - > USB转换器(实际上腻子可以用来做以及)

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)在代码::块打开以下文件BlackUART.cpp, BlackSPI.cpp, BlackI2C.cpp并添加

#include <unistd.h>

之后#include "BlackUART.h" ,在“unistd.h中”包括所有类似休眠)功能(),开(),关闭(...否则似乎缺少

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(例如/家庭/ UART)创建目录和所有的BlackLib文件和复制的main.cpp到这个文件夹中

7)打开腻子并导航到文件夹: 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

取决于导线的连接



Answer 2:

看来我设法解决它自己,有些nooblike行为不包括所有的cpp文件,但甚至更多,我还需要的#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来seperately编译库,时间多做一些挖掘和学习。



Answer 3:

我BlackLib的创造者,YiğitYÜCE。 你自己找到答案。 您在您的评论中提到的生成文件将于近期公布。



文章来源: how to compile blacklib (c++)