Boost is a set of free and open-source libraries for the C++ programming language. The libraries provide functionality in a wide range of areas such as smart pointers, thread management, containers, algorithms, numeric processing, regular expressions, and more.
You can use it with openLinux projects on Fibocom modules to improve your project development.
2. Requirements:- NL668-LA-Module (or any other Fibocom Module)
- Linux OS*
- VSCode
- ADB (Android Debug Bridge)
*Obs.: This tutorial was made on a Linux computer, but you can easily do the same on a Windows computer.
3. Setting EnvironmentOpen Linux terminal and Install gcc, g++ and dependencies to ARM crosscompilation:
sudo apt install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev build-essential bison flex libssl-dev bc
sudo apt install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
Now download and extract boost (we will use version 1.52.0):
https://www.boost.org/users/history/version_1_52_0.html
Open boost_1_52_0 folder with VSCode:
Now run bootstrap.sh
on terminal:
./bootstrap.sh
Bootstrap has generated some files into boost_1_52_0 folder.
Open file project-config.jam
and add the gcc arm settings:
using gcc ;
using gcc : arm : arm-linux-gnueabi-g++ ;
The file should be like this:
Now run sudo ./b2 install
to compile and install dependencies.
sudo ./b2 install
Let’s compile the hello world application from boost. The source code is on tools/build/v2/example/hello/hello.cpp
as you can see below:
The application./b2 on boost root folder will be used to compile the application. It will be necessary to add some parameters to define which example we want to compile, which toolset (architecture) we will use, build variant (release or debug) and the type of link for libraries (static or dynamic).
I really recommend you to use the static link and runtime parameters. It will create an larger file, but will avoid missing links. You can optimize your application and set to dynamic link on future.
So, run this command on boost root folder:
./b2 tools/build/v2/example/hello toolset=gcc-arm link=static runtime-link=static variant=release
Now check the output folder on tools/build/v2/example/hello/bin/gcc-arm/release/link-static/runtime-link-static
:
Open the output folder, enable read-and-write partition on your module and send the binary using adb push:
cd tools/build/v2/example/hello/bin/gcc-arm/release/link-static/runtime-link-static
adb shell mount -o rw,remount /
adb push hello /home/
Now, use adb shell
to access your module and run the hello binary:
adb shell
cd home
ls
./hello
Now, lets create some application that will use some boost embedded library (lambda.hpp
on this case).
Create a folder called myapplication
on boost root folder:
Now you will need to create the files myapplication.cpp and jamroot.jam with the following code inside:
myapplication.cpp
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " \\n" );
}
jamroot.jam
exe myapplication : myapplication.cpp ;
Compile it running the./b2 from boost root folder:
./b2 myapplication toolset=gcc-arm link=static runtime-link=static variant=release
Open the output folder, enable read-and-write partition on your module and send the binary using adb push:
cd myapplication/bin/gcc-arm/release/link-static/runtime-link-static/
adb shell mount -o rw,remount /
adb push myapplication /home/
Now, use adb shell
to access your module and run the hello binary:
adb shell
cd home
ls
./myapplication
Input any number and it will be multiplied by 3 (exit with Ctrl + Z when necessary):
Or, input the numbers via echo and pipe:
echo 5 7 10 | ./myapplication
Here is some considerations if you are having issues on this tutorial:
project-config.jam
You can specify the version of your primary installed g++ as bellow:
using gcc : 11.2 : g++-11 ;
using gcc : arm : arm-linux-gnueabi-g++ ;
Or just remove the first line for x86 architecture and just use the second line:
using gcc : arm : arm-linux-gnueabi-g++ ;
Install a newer libboost on your OS:
Maybe you can have some incompatibilities related to the version of libboost and the gcc version of your pc. So you can b2 directly on your linux pc using apt:
sudo apt install libboost-all-dev
OR
sudo apt install libboost1.74-all-dev
Comments