We are going to create a simple application that creates three time points and compares them to each other.
- In your ~/test working directory, create a subdirectory called chrono.
- Use your favorite text editor to create a chrono.cpp file in the chrono subdirectory.
- Put the following code snippet into the file:
#include <iostream>
#include <chrono>
using namespace std::chrono_literals;
int main() {
auto a = std::chrono::system_clock::now();
auto b = a + 1s;
auto c = a + 200ms;
std::cout << "a < b ? " << (a < b ? "yes" : "no") << std::endl;
std::cout << "a < c ? " << (a < c ? "yes" : "no") << std::endl;
std::cout << "b < c ? " << (b < c ? "yes" : "no") << std::endl;
return 0;
}
- Create a CMakeLists.txt file containing build rules for our program:
cmake_minimum_required(VERSION 3.5.1)
project(chrono)
add_executable(chrono chrono.cpp)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CXX_FLAGS "--std=c++14")
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabi-g++)
You can now build and run the application.