CMAKE can't find TensorRT

I have untar’d TensorRT to /usr/local/cuda/TensorRT and added the following ENV variables in .bashrc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/TensorRT:/usr/local/cuda/TensorRT/targets/x86_64-linux-gnu/lib/

export CUDNN_INSTALL_DIR=/usr/local/cuda/lib64

Having done so, the sample MNIST builds and runs successfully,

When I try to build another package (pointpillars, autoware) it fails.

I tried creating a dummy cmake project with some extracts from pointpillars to try to understand which part fails:

find_library(NVINFER NAMES libnvinfer.so)
find_library(NVPARSERS NAMES nvparsers)
find_library(NVONNXPARSERS NAMES nvonnxparser)
if(NVINFER)
   message("TensorRT is available!")
   message("NVINFER: ${NVINFER}")
   message("NVPARSERS: ${NVPARSERS}")
   message("NVONNXPARSERS: ${NVONNXPARSERS}")
   set(TRT_AVAIL ON)
else()
  message("TensorRT is NOT Available")
  set(TRT_AVAIL OFF)
endif()

This fails to find libnvinfer.so - which I know is located in /usr/local/cuda/TensorRT/targets/x86_64-linux-gnu/lib/

So my question is: What is the best way to let CMake know how to find TensorRT ?

I’m on Ubuntu server 16.04, CUDA 10.0 due to other advice I have received in this forum from Nvidia, I have installed cuda from the .run and CuDNN from the .tgz

Hello! I meet the same problem with you. Could you please tell me that how you access this issue finally? Thanks in advance for the help!

I solved it by adding set(CMAKE_PREFIX_PATH "/myhome/TensorRT-5.1.5.0/lib") to CMakeLists.txt

4 Likes

Hi,

You can use below example to find tensorrt using cmake.

list(APPEND PLUGINS "nvinfer")
list(APPEND PLUGINS "nvonnxparser")
list(APPEND PLUGINS "nvparsers")

foreach(libName ${PLUGINS})
    find_library(${libName}_lib NAMES ${libName} "/usr" PATH_SUFFIXES lib)
    list(APPEND PLUGIN_LIBS "${${libName}_lib}")
endforeach()

Hope it will help you

2 Likes

I added also this line and it helped me with the migration from trt5 to trt7
list(APPEND PLUGINS "nvinfer_plugin")

Thank you so much!

You really saved my day!
After building TensorRT from source, I ran into the problem that the source does not have a “TensorRTConfig.cmake” so there’s no option to use “find_package(TensorRT REQUIRED)” which would make more sense. But, again your solution solved the issue. Thanx!