Building and Running C++ Samples#
You can find the C++ samples in GitHub: TensorRT C++ Samples. For a complete list of C++ samples, refer to the Sample Explorer, or start with the Quick Start section for beginner-friendly options.
Every C++ sample includes a README.md file that provides detailed information about how the sample works, sample code, and step-by-step instructions on how to run and verify its output.
Building C++ Samples for All Platforms
To build all the samples, use the following commands:
$ export TRT_ROOT=/path/to/tensorrt
$ cd <cloned_tensorrt_dir>
$ mkdir build && cd build
$ cmake .. \
-DCMAKE_PREFIX_PATH=$TRT_ROOT \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=`pwd`/out \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=`pwd`/out \
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=`pwd`/out \
-DBUILD_SAMPLES=ON \
-DBUILD_PARSERS=OFF \
-DBUILD_PLUGINS=OFF
$ cmake --build . --parallel 4
CMAKE_PREFIX_PATH points at the root of the TensorRT installation, not at its
lib subdirectory: it is /usr for Debian and RPM packages, or the
extracted directory for a tar or zip package. The build locates TensorRT through
the CMake configuration files in that package.
Sample binaries are available under <cloned_tensorrt_dir>/build/out. The
three output directory settings put them there; without them, CMake writes each
sample to its own subdirectory under build/samples.
Samples Installation
Samples are no longer included in release packages. To build TensorRT samples, fetch them from GitHub and build as shown below.
export TRT_ROOT=/path/to/tensorrt
git clone -b main https://github.com/NVIDIA/TensorRT.git
cd TensorRT
git submodule update --init --recursive
mkdir build && cd build
cmake .. \
-DCMAKE_PREFIX_PATH=$TRT_ROOT \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=`pwd`/out \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=`pwd`/out \
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=`pwd`/out \
-DBUILD_SAMPLES=ON \
-DBUILD_PARSERS=OFF \
-DBUILD_PLUGINS=OFF
cmake --build . --parallel 4
Running C++ Samples on Linux
To run a single sample on Linux:
$ cd <cloned_tensorrt_dir>/build/out
$ ./<sample_bin>
Running C++ Samples on Windows
To run a single sample on Windows:
> cd <cloned_tensorrt_dir>\build\out
> .\<sample_bin>