Error while linking sampleOnnxMNIST tutorial

Description

I am trying to link one of the sample tutorials (sampleOnnxMNIST) using CMakeLists (attached).

Here is the linking error I get:

[100%] Linking CXX executable infer_LDC
/usr/bin/ld: CMakeFiles/infer_LDC.dir/main.cpp.o: in function `SampleOnnxMNIST::build()':
main.cpp:(.text+0xf35): undefined reference to `createInferBuilder_INTERNAL'
/usr/bin/ld: main.cpp:(.text+0xf91): undefined reference to `createNvOnnxParser_INTERNAL'
/usr/bin/ld: main.cpp:(.text+0x1154): undefined reference to `createInferRuntime_INTERNAL'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/main.cpp.o: in function `createBuilder()':
main.cpp:(.text+0x11): undefined reference to `createInferBuilder_INTERNAL'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/main.cpp.o: in function `createRuntime()':
main.cpp:(.text+0x31): undefined reference to `createInferRuntime_INTERNAL'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/main.cpp.o: in function `createRefitter(nvinfer1::ICudaEngine&)':
main.cpp:(.text+0x51): undefined reference to `createInferRefitter_INTERNAL'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/main.cpp.o: in function `createONNXParser(nvinfer1::INetworkDefinition&)':
main.cpp:(.text+0x71): undefined reference to `createNvOnnxParser_INTERNAL'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/home/workpc/Downloads/software/TensorRT/TensorRT-8.6.1.6/samples/common/sampleOptions.cpp.o: in function `sample::(anonymous namespace)::removeSingleQuotationMarks(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
sampleOptions.cpp:(.text+0x6452): undefined reference to `sample::splitToStringVec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/home/workpc/Downloads/software/TensorRT/TensorRT-8.6.1.6/samples/common/sampleOptions.cpp.o: in function `std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > sample::(anonymous namespace)::splitNameAndValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
sampleOptions.cpp:(.text+0x65cd): undefined reference to `sample::splitToStringVec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)'
/usr/bin/ld: sampleOptions.cpp:(.text+0x6866): undefined reference to `sample::splitToStringVec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/home/workpc/Downloads/software/TensorRT/TensorRT-8.6.1.6/samples/common/sampleOptions.cpp.o: in function `std::vector<int, std::allocator<int> > sample::(anonymous namespace)::stringToValue<std::vector<int, std::allocator<int> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
sampleOptions.cpp:(.text+0x8533): undefined reference to `sample::splitToStringVec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/home/workpc/Downloads/software/TensorRT/TensorRT-8.6.1.6/samples/common/sampleOptions.cpp.o: in function `std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> > > sample::(anonymous namespace)::splitNameAndValue<std::vector<int, std::allocator<int> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
sampleOptions.cpp:(.text+0x8739): undefined reference to `sample::splitToStringVec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)'
/usr/bin/ld: CMakeFiles/infer_LDC.dir/home/workpc/Downloads/software/TensorRT/TensorRT-8.6.1.6/samples/common/sampleOptions.cpp.o:sampleOptions.cpp:(.text+0x89a6): more undefined references to `sample::splitToStringVec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)' follow
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/infer_LDC.dir/build.make:196: infer_LDC] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/infer_LDC.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

This example builds file if I navigate to
TensorRT-8.6.1.6/samples/sampleOnnxMNIST/
and type make.

Any ideas please?

Environment

TensorRT Version: TensorRT-8.6.1.6
GPU Type: RTX 2060
Nvidia Driver Version: 535
CUDA Version: 12.2
CUDNN Version:
Operating System + Version: Ubuntu 22.04
Python Version (if applicable):
TensorFlow Version (if applicable):
PyTorch Version (if applicable):
Baremetal or Container (if container which image + tag):
CMakeLists.txt (1.8 KB)

Hi,

Could you please upgrade to the latest Cmake version and try again?
If you continue to have problems, please visit Issues · NVIDIA/TensorRT · GitHub for better help on compilation errors.

Thank you.

I have the same problem on Tensor_RT v8.6.1, my log is below

[ 95%] Building CXX object samples/sampleCharRNN/CMakeFiles/sample_char_rnn.dir/__/common/sampleUtils.cpp.o
[ 95%] Building CXX object samples/trtexec/CMakeFiles/trtexec.dir/__/common/sampleInference.cpp.o
[ 95%] Building CXX object samples/trtexec/CMakeFiles/trtexec.dir/__/common/sampleOptions.cpp.o
[ 95%] Building CXX object samples/sampleCharRNN/CMakeFiles/sample_char_rnn.dir/__/common/logger.cpp.o
[ 95%] Building CXX object samples/trtexec/CMakeFiles/trtexec.dir/__/common/sampleReporting.cpp.o
[ 95%] Building CXX object samples/trtexec/CMakeFiles/trtexec.dir/__/common/sampleUtils.cpp.o
[ 95%] Building CXX object samples/trtexec/CMakeFiles/trtexec.dir/trtexec.cpp.o
[ 95%] Linking CXX executable ../../out/sample_onnx_mnist_coord_conv_ac
[ 96%] Linking CXX executable ../../out/sample_onnx_mnist
[ 96%] Built target sample_onnx_mnist_coord_conv_ac
[ 96%] Building CXX object samples/trtexec/CMakeFiles/trtexec.dir/__/common/logger.cpp.o
[ 96%] Linking CXX executable ../../out/sample_named_dimensions
[ 96%] Built target sample_onnx_mnist
[ 96%] Built target sample_named_dimensions
[ 97%] Linking CXX executable ../../out/sample_io_formats
[ 97%] Built target sample_io_formats
[ 98%] Linking CXX executable ../../out/sample_dynamic_reshape
[ 98%] Built target sample_dynamic_reshape
[ 98%] Linking CXX executable ../../out/sample_algorithm_selector
[ 98%] Built target sample_algorithm_selector
[ 98%] Linking CXX executable ../../out/sample_int8_api
[ 98%] Built target sample_int8_api
[ 98%] Linking CXX executable ../../out/sample_char_rnn
/usr/bin/ld: CMakeFiles/sample_char_rnn.dir/sampleCharRNN.cpp.o: in function `SampleCharRNNBase::convertRNNWeights(nvinfer1::Weights, int)':
sampleCharRNN.cpp:(.text+0x1a08): undefined reference to `nvinfer1::utils::transposeSubBuffers(void*, nvinfer1::DataType, int, int, int)'
/usr/bin/ld: sampleCharRNN.cpp:(.text+0x1a2f): undefined reference to `nvinfer1::utils::transposeSubBuffers(void*, nvinfer1::DataType, int, int, int)'
/usr/bin/ld: CMakeFiles/sample_char_rnn.dir/sampleCharRNN.cpp.o: in function `SampleCharRNNBase::constructNetwork(std::unique_ptr<nvinfer1::IBuilder, samplesCommon::InferDeleter>&, std::unique_ptr<nvinfer1::INetworkDefinition, samplesCommon::InferDeleter>&, std::unique_ptr<nvinfer1::IBuilderConfig, samplesCommon::InferDeleter>&)':
sampleCharRNN.cpp:(.text+0x330d): undefined reference to `nvinfer1::utils::transposeSubBuffers(void*, nvinfer1::DataType, int, int, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [samples/sampleCharRNN/CMakeFiles/sample_char_rnn.dir/build.make:158: out/sample_char_rnn] Error 1
make[1]: *** [CMakeFiles/Makefile2:1655: samples/sampleCharRNN/CMakeFiles/sample_char_rnn.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable ../../out/trtexec
[100%] Built target trtexec
make: *** [Makefile:156: all] Error 2