Native Compilation On Nvidia Drive PX 2 Hardware

This article describes how to compile a PolySync Example natively on DRIVE PX 2 hardware to quickly validate functionality. Please see Linux SDK 4.1 for DRIVE PX 2 - Development Guide - 4.1.8.0 release for additional information about setting up cross compilation toolchains for a more typical development process.

PolySync Core libraries and executables are cross-compiled using the Tegra cross-compilation toolchain provided by DriveInstall 4.1.8.0 Linux SDK. The cross-compilation toolchain provided by DriveInstall uses gcc and g++ versions 4.9, this is different from the default versions that are installed with Ubuntu Xenial after flashing the Tegra boards. Below are the steps to setup and use the correct compiler for building the examples natively.

Setup update-alternatives for switching between compilers

1. Install gcc/g++ v4.9

sudo apt install gcc-4.9 g++-4.9

2. Install alternative linkage

10 and 20 represent priority - 4.9 would be the default in the case below

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/aarch64-linux-gnu-gcc-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/aarch64-linux-gnu-g++-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/aarch64-linux-gnu-gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/aarch64-linux-gnu-g++-5 10

3. Sanity check

update-alternatives --list gcc
update-alternatives --list g++
gcc --version
g++ --version

4. Switch between alternatives (4.9 should be selected already as the default)

sudo update alternatives --config gcc
sudo update alternatives --config g++

Build and run examples

git clone https://github.com/PolySync/polysync-core-cpp-examples.git
cd polysync-core-cpp-examples/PublishSubscribe
mkdir build && cd build
cmake ..
make
./polysync-publisher-subscriber-cpp 
# ctrl-c to exit