TensorRT学习笔记--Linux基于VSCode利用CMake编译C++ Sample

目录

1--前言

2--CMakeLists.txt编写

3--实例


1--前言

博主系统环境如下:

        System:Ubuntu 20.04

        OpenCV:4.70

        Cuda:11.3

        Tensor RT:8.2.5.1

2--CMakeLists.txt编写

        需要使用OpenCV、TensorRT以及Cuda相应的头文件和动态库:

cmake_minimum_required(VERSION 3.13)
project(TensorRT_test)
set(CMAKE_CXX_STANDARD 11)

set(SAMPLES_COMMON_SOURCES "/home/liujinfu/Downloads/TensorRT-8.2.5.1/samples/common/logger.cpp")
add_executable(TensorRT_test sampleMNIST.cpp ${SAMPLES_COMMON_SOURCES})

# add OpenCV
find_package(OpenCV REQUIRED)
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})

# add TensorRT8
include_directories(/home/liujinfu/Downloads/TensorRT-8.2.5.1/include)
include_directories(/home/liujinfu/Downloads/TensorRT-8.2.5.1/samples/common)
set(TENSORRT_LIB_PATH "/home/liujinfu/Downloads/TensorRT-8.2.5.1/lib")
file(GLOB LIBS "${TENSORRT_LIB_PATH}/*.so")

# add CUDA
find_package(CUDA 11.3 REQUIRED)
message("CUDA_LIBRARIES:${CUDA_LIBRARIES}")
message("CUDA_INCLUDE_DIRS:${CUDA_INCLUDE_DIRS}")
include_directories(${CUDA_INCLUDE_DIRS})

# link
target_link_libraries(TensorRT_test ${LIBS} ${CUDA_LIBRARIES} ${OpenCV_LIBS})

3--实例

        基于 Tensor RT 8.2.5 提供的 sampleMNIST.cpp 文件,在 VSCode 下利用 CMake 编译成可执行文件:

mkdir build 

cd build

cmake ..

make

        编译过程:

TensorRT学习笔记--Linux基于VSCode利用CMake编译C++ Sample_第1张图片

TensorRT学习笔记--Linux基于VSCode利用CMake编译C++ Sample_第2张图片

        运行测试:

./TensorRT_test -d /home/liujinfu/Downloads/TensorRT-8.2.5.1/data/mnist

TensorRT学习笔记--Linux基于VSCode利用CMake编译C++ Sample_第3张图片

         当输入数字6时,结果识别为6,编译得到的可执行文件运行结果正确。

你可能感兴趣的:(TensorRT学习笔记,学习)