如何编译 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 程序,但我无法让这个程序运行。因此,我们将不胜感激。
看来我自己设法修复了它,有些菜鸟行为不包括所有 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 来单独编译库,是时候进行更多挖掘和学习了。
我是 BlackLib 的创建者 Yiğit YÜCE。你自己找到了答案。您在评论中提到的 makefile 将很快发布。
完整指南如何在 BEAGLEBONE BLACK(修订版 C)上直接编译 BLACKLIB 运行ning ANGSTROM:
程序:
Putty - 从 Windows 与 BBB 通信(使用带 USB 电缆的 SSH)
WinSCP - 直接在 BBB 上管理(上传、创建、删除)文件
Code::Blocks - 编写C++程序
可选
Termite 2.9 - 从 UART<->USB 转换器发送和接收 UART 传输(实际上 Putty 也可以用来做到这一点)
1) 从 official site
获取 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
取决于电线的连接
我正在运行一个 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 程序,但我无法让这个程序运行。因此,我们将不胜感激。
看来我自己设法修复了它,有些菜鸟行为不包括所有 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 来单独编译库,是时候进行更多挖掘和学习了。
我是 BlackLib 的创建者 Yiğit YÜCE。你自己找到了答案。您在评论中提到的 makefile 将很快发布。
完整指南如何在 BEAGLEBONE BLACK(修订版 C)上直接编译 BLACKLIB 运行ning ANGSTROM:
程序:
Putty - 从 Windows 与 BBB 通信(使用带 USB 电缆的 SSH)
WinSCP - 直接在 BBB 上管理(上传、创建、删除)文件
Code::Blocks - 编写C++程序
可选
Termite 2.9 - 从 UART<->USB 转换器发送和接收 UART 传输(实际上 Putty 也可以用来做到这一点)
1) 从 official site
获取 BlackLib2) 解压缩库并将以下文件复制到单独的文件夹中:
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
取决于电线的连接