Compiling and Linking for Arm - 2023.1 English

Vitis Unified Software Platform Documentation: Application Acceleration Development (UG1393)

Document ID
UG1393
Release Date
2023-07-17
Version
2023.1 English
Tip: Set up the command shell or window as described in Setting Up the Vitis Environment prior to running the tools.

For embedded processor-based platforms, the host program (host.exe), is cross-compiled and linked for an Arm processor using the GNU Arm cross-compiler version of g++ in the following two step process:

Tip: aarch64 is used for AMD Zynq™ AMD UltraScale+™ (A53) and AMD Versal™ (A72) devices. aarch32 is used for Zynq 7000 SoC (A9) and the tool chain is in a different location.
  1. Compile the host.cpp into an object file (.o):
    $XILINX_VITIS/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ -c \
    -D__USE_XOPEN2K8 -I$SYSROOT/usr/include/xrt -I$XILINX_VIVADO/include \
    -I$SYSROOT/usr/include -fmessage-length=0 -std=c++14 --sysroot=$SYSROOT \
    -o src/host.o ../src/host.cpp
  2. Link the object file with required libraries to build the executable application.
    $XILINX_VITIS/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ -l \
    -lxrt_coreutil -lpthread -lrt -lstdc++ -lgmp -L$SYSROOT/usr/lib/ \
    --sysroot=$SYSROOT -o host.exe src/host.o 

When compiling the application for use with an embedded process, you must specify the sysroot for the application. The sysroot is part of the platform where the basic system root file structure is defined, and is installed as described in Installing Embedded Platforms .

Important: The above examples rely on the use of $SYSROOT environment variable that must be used to specify the location of the sysroot for your embedded platform.

The following are key elements to compiling the host code for an edge platform:

Compilation
  • -I$SYSROOT/usr/include
  • -I$SYSROOT/usr/include/xrt
  • -std=c++14: Define the C++ language standard. Compiling host code with XRT native C++ API requires C++ standard with -std=c++14 or newer. However, on GCC versions older than 4.9.0, use -std=c++1y instead.
Linking
  • -L$SYSROOT/usr/lib: Library paths location.
  • -lxrt_coreutil: Required library for use with the XRT native API.
  • -pthread: Required by XRT library for multithreading.

Building OpenCL API Host Code

The Vitis application acceleration development flow also supports the use of OpenCL API to program your host application. Building OpenCL applications using g++ uses the following command line:
g++ -g -std=c++1y -I$XILINX_XRT/include -L$XILINX_XRT/lib -o host.exe host.cpp \
-lOpenCL -pthread

The only difference is the use of the OpenCL library for the OpenCL API in place of the xrt_coreutil library for the XRT native API.

Note: In Vitis Accel_Examples you can see the addition of xcl2.cpp source file, and the -I../xcl2 include statement. These additions to the host program and g++ command provide access to helper utilities used by the example code, but are generally not required for your own code.