undefined reference to `createInferBuilder_INTERNAL' whe I run sampleOnnxMNIST.cpp

I am using TensorRT5 with Jetson Xavier. I am passing cuda and tensorrt dependencies.

g++ new_file.cpp -I/usr/local/cuda/include -I/usr/src/tensorrt/samples/common -std=c++11

Below is the whole log of Errors:

adas_vehicle@adas:/usr/src/tensorrt/samples/sampleOnnxMNIST$ sudo g++ sampleOnnxMNIST.cpp -I/usr/local/cuda/include -I/usr/src/tensorrt/samples/common -std=c++11
[sudo] password for adas_vehicle:
/tmp/cc7ZwYbJ.o: In function nvinfer1::(anonymous namespace)::createInferBuilder(nvinfer1::ILogger&)': sampleOnnxMNIST.cpp:(.text+0x19): undefined reference to createInferBuilder_INTERNAL’
/tmp/cc7ZwYbJ.o: In function nvinfer1::(anonymous namespace)::createInferRuntime(nvinfer1::ILogger&)': sampleOnnxMNIST.cpp:(.text+0x38): undefined reference to createInferRuntime_INTERNAL’
/tmp/cc7ZwYbJ.o: In function nvonnxparser::(anonymous namespace)::createParser(nvinfer1::INetworkDefinition&, nvinfer1::ILogger&)': sampleOnnxMNIST.cpp:(.text+0x62): undefined reference to createNvOnnxParser_INTERNAL’
/tmp/cc7ZwYbJ.o: In function doInference(nvinfer1::IExecutionContext&, float*, float*, int)': sampleOnnxMNIST.cpp:(.text+0x47f): undefined reference to cudaMalloc’
sampleOnnxMNIST.cpp:(.text+0x4de): undefined reference to cudaMalloc' sampleOnnxMNIST.cpp:(.text+0x514): undefined reference to cudaStreamCreate’
sampleOnnxMNIST.cpp:(.text+0x576): undefined reference to cudaMemcpyAsync' sampleOnnxMNIST.cpp:(.text+0x606): undefined reference to cudaMemcpyAsync’
sampleOnnxMNIST.cpp:(.text+0x63c): undefined reference to cudaStreamSynchronize' sampleOnnxMNIST.cpp:(.text+0x648): undefined reference to cudaStreamDestroy’
sampleOnnxMNIST.cpp:(.text+0x65a): undefined reference to cudaFree' sampleOnnxMNIST.cpp:(.text+0x696): undefined reference to cudaFree’
collect2: error: ld returned 1 exit status

Hello,

Looks like you are not linking cuda and tensorrt correctly. Since you are usng the onnxMNIST sample, please reference the associated makefile and makefile.config for how to -l the appropriate libraries and -i the necessary header files.