Building the Host Program
The host program, written in C/C++ using OpenCL™ API calls, is built using the GNU C++ compiler (g++
) which is based on GNU compiler collection (GCC). Each
source file is compiled to an object file (.o) and
linked with the Xilinx runtime (XRT) shared library
to create the executable which runs on the host CPU.
g++
supports many standard GCC options which are not documented here. For
information refer to the GCC Option Summary.Compiling and Linking for x86
g++
compiler.
g++ ... -c <source_file1> <source_file2> ... <source_fileN>
-l
option.g++ ... -l <object_file1.o> ... <object_fileN.o>
Compiling and linking for x86 follows the standard g++
flow. The only requirement is to include the XRT header files and link the XRT shared
libraries.
When compiling the source code, the following g++
options are required:
-I$XILINX_XRT/include/
: XRT include directory.-I$XILINX_VIVADO/include
: Vivado tools include directory.-std=c++11
: Define the C++ language standard.
When linking the executable, the following g++ options are required:
-L$XILINX_XRT/lib/
: Look in XRT library.-lOpenCL
: Search the named library during linking.-lpthread
: Search the named library during linking.-lrt
: Search the named library during linking.-lstdc++
: Search the named library during linking.
-I../libs/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. Compiling and Linking for Arm
The host program (host.exe
), is cross-compiled
for an Arm processor, and linked using the
following two step process:
- Compile the host.cpp into an object file
(.o) using the GNU Arm cross-compiler version of
g++
:Note:aarch64
is used for Zynq® UltraScale+™ (A53) devices.aarch32
is used for Zynq-7000 SoC (A9) and the tool chain is in a different location.$XILINX_VITIS/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ \ -D__USE_XOPEN2K8 -I$SYSROOT/usr/include/xrt -I$XILINX_VIVADO/include \ -I$SYSROOT/usr/include -c -fmessage-length=0 -std=c++14 \ --sysroot=$SYSROOT -o src/host.o ../src/host.cpp
- Link the object file with required libraries to build the executable
application.
$XILINX_VITIS/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ \ -o host.exe src/host.o -lxilinxopencl -lpthread -lrt -lstdc++ -lgmp -lxrt_core \ -L$SYSROOT/usr/lib/ --sysroot=$SYSROOT
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.
$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
-
- The cross compiler needed is the
aarch64-linux-gnu-g++
found in the Vitis installation hierarchy. - The required include paths are:
- $SYSROOT/usr/include
- $SYSROOT/usr/include/xrt
- $XILINX_VIVADO/include
- The cross compiler needed is the
- Linking
-
- $SYSROOT/usr/lib: Library paths location.
- xilinxopencl: XRT required library.
- pthread: XRT required library.
- rt: XRT required library.
- stdc++: XRT required library.
- gmp: XRT required library.
- xrt_core: XRT required library.