Vscode+cmake to debug tensorrt's official samples' program


The official tensorrt samples only support visual studio 2017/2019, Now
I use vscode installed with camke to debug sampleOnnxMNIST under TensorRT-’s samples folder, error happens during linking see log file


TensorRT Version:
GPU Type: RTX3060
Nvidia Driver Version: 515
CUDA Version: 11.3
CUDNN Version:
Operating System + Version: ubuntu20.04
**vscode Version: 1.69.1

Relevant Files

my CMakeLists.txt file is
CMakeLists.txt (1.3 KB)
vscode json file
tasks.json (713 Bytes)
launch.json (253 Bytes)
c_cpp_properties.json (782 Bytes)

cmake logging info are

hitbuyi@hitbuyi-Dell-G15-5511:~/cuda/trt1/samples/sampleOnnxMNIST/build$ cmake …
– The C compiler identification is GNU 9.4.0
– The CXX compiler identification is GNU 9.4.0
– Check for working C compiler: /usr/bin/cc
– Check for working C compiler: /usr/bin/cc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Configuring done
– Generating done
– Build files have been written to: /home/hitbuyi/cuda/trt1/samples/sampleOnnxMNIST/build
hitbuyi@hitbuyi-Dell-G15-5511:~/cuda/trt1/samples/sampleOnnxMNIST/build$ make
Scanning dependencies of target sampleOnnxMNIST
[ 50%] Building CXX object CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o
[100%] Linking CXX executable sampleOnnxMNIST
/usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function SampleOnnxMNIST::build()': sampleOnnxMNIST.cpp:(.text+0x198): undefined reference to sample::gLogger’
/usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x26d): undefined reference to sample::gLogger' /usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x3b2): undefined reference to sample::gLogger’
/usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x4bd): undefined reference to sample::gLogError' /usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x578): undefined reference to sample::gLogError’
/usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x5d2): undefined reference to sample::gLogError' /usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x693): undefined reference to sample::gLogError’
/usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function SampleOnnxMNIST::constructNetwork(std::unique_ptr<nvinfer1::IBuilder, samplesCommon::InferDeleter>&, std::unique_ptr<nvinfer1::INetworkDefinition, samplesCommon::InferDeleter>&, std::unique_ptr<nvinfer1::IBuilderConfig, samplesCommon::InferDeleter>&, std::unique_ptr<nvonnxparser::IParser, samplesCommon::InferDeleter>&)': sampleOnnxMNIST.cpp:(.text+0x810): undefined reference to sample::gLogger’
/usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function SampleOnnxMNIST::infer()': sampleOnnxMNIST.cpp:(.text+0xa61): undefined reference to sample::gLogError’
/usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function SampleOnnxMNIST::processInput(samplesCommon::BufferManager const&)': sampleOnnxMNIST.cpp:(.text+0xd5b): undefined reference to sample::gLogInfo’
/usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0xde8): undefined reference to sample::gLogInfo' /usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0xe3e): undefined reference to sample::gLogInfo’
/usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function SampleOnnxMNIST::verifyOutput(samplesCommon::BufferManager const&)': sampleOnnxMNIST.cpp:(.text+0x10b7): undefined reference to sample::gLogInfo’
/usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x1180): undefined reference to sample::gLogInfo' /usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o:sampleOnnxMNIST.cpp:(.text+0x12fc): more undefined references to sample::gLogInfo’ follow
/usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function main': sampleOnnxMNIST.cpp:(.text+0x17d1): undefined reference to sample::gLogError’
/usr/bin/ld: sampleOnnxMNIST.cpp:(.text+0x1895): undefined reference to sample::gLogInfo' /usr/bin/ld: CMakeFiles/sampleOnnxMNIST.dir/sampleOnnxMNIST.cpp.o: in function samplesCommon::BufferManager::memcpyBuffers(bool, bool, bool, CUstream_st* const&)‘:
sampleOnnxMNIST.cpp:(.text._ZN13samplesCommon13BufferManager13memcpyBuffersEbbbRKP11CUstream_st[_ZN13samplesCommon13BufferManager13memcpyBuffersEbbbRKP11CUstream_st]+0x1f5): undefined reference to sample::gLogError' /usr/bin/ld: sampleOnnxMNIST.cpp:(.text._ZN13samplesCommon13BufferManager13memcpyBuffersEbbbRKP11CUstream_st[_ZN13samplesCommon13BufferManager13memcpyBuffersEbbbRKP11CUstream_st]+0x252): undefined reference to sample::gLogError’
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/sampleOnnxMNIST.dir/build.make:84: sampleOnnxMNIST] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/sampleOnnxMNIST.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

1, cmake … ok
2, make error, it prompts sample::gLogInfo not found, but I had inlcude int CMakeLists.txt file and vscode’s c_cpp_properties.json file

so, what are my problems? any help will be appreciated.

Please refer to the below link for Sample guide.

Refer to the installation steps from the link if in case you are missing on anything

However suggested approach is to use TRT NGC containers to avoid any system dependency related issues.

In order to run python sample, make sure TRT python packages are installed while using NGC container.

In case, if you are trying to run custom model, please share your model and script with us, so that we can assist you better.

I just found the problem, the official samples doesn’t build via cmake, it is built by makefile directorly, when enter ‘make’ command, it produces lots of *.o files in bin/chobj/sampleOnnxMNIST, bin/dchobj/sampleOnnxMNIST folds,

If you use CMAKE to build them ,you should include these *.o files in CMakeLists.txt, in my case, I add missed *.o file as

add_executable(sampleOnnxMNIST sampleOnnxMNIST.cpp

it works for me

Thanks any way

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.