Compiling and Linking for x86 - 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.
Each source file of the host application is compiled into an object file (.o) using the g++ compiler.
g++ ... -c <source_file1> <source_file2> ... <source_fileN>
The generated object files (.o) are linked with the Xilinx Runtime (XRT) shared library to create the executable host program. Linking is performed using the -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.

The host application can be written in native C++ using the Xilinx Runtime (XRT) native C++ API or industry standard OpenCL™ API. The required include files and libraries depend on the API your host application uses, and any specific requirements of your host code.

To use the native XRT API, the host application must link with the xrt_coreutil library. The command line uses a few different settings as shown in the following example, which combines compilation and linking:

g++ -g -std=c++14 -I$XILINX_XRT/include -L$XILINX_XRT/lib -o host.exe host.cpp \
-lxrt_coreutil -pthread

When compiling the source code, the following g++ options are required:

  • -I$XILINX_XRT/include/: XRT include directory.
  • -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.

When linking the executable, the following g++ options are required:

  • -L$XILINX_XRT/lib/: Look in XRT library.
  • -lxrt_coreutil: Search the named library during linking.
  • -pthread: Search the named library during linking.

Building OpenCL API Host Code

The AMD 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.