TensorRT (C++ API) undefined reference to `createNvOnnxParser_INTERNAL'
I am trying to create a tensorrt engine from ONNX model using the TensorRT C++ API. I have written code to read, serialize and write a tensorrt engine to disk as per the documentation. I have installed tensorrt7 on colab using debian installation instructions.
This is my c++ code that I am compiling using g++ rnxt.cpp -o rnxt
#include &lt;cuda_runtime_api.h&gt;
#include &lt;NvOnnxParser.h&gt;
#include &lt;NvInfer.h&gt;

#include &lt;cstdlib&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;

class Logger : public nvinfer1::ILogger           
 {
     void log(Severity severity, const char* msg) override
     {
         // suppress info-level messages
         if (severity != Severity::kINFO)
             std::cout &lt;&lt; msg &lt;&lt; std::endl;
     }
 } gLogger;


int main(){

    int maxBatchSize = 32;

    nvinfer1::IBuilder* builder = nvinfer1::createInferBuilder(gLogger);
    const auto explicitBatch = 1U &lt;&lt; static_cast&lt;uint32_t&gt;(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);  
    nvinfer1::INetworkDefinition* network = builder-&gt;createNetworkV2(explicitBatch);

    nvonnxparser::IParser* parser = nvonnxparser::createParser(*network, gLogger);
    
    
    parser-&gt;parseFromFile(&quot;saved_resnext.onnx&quot;, 1);
    for (int i = 0; i &lt; parser-&gt;getNbErrors(); ++i)
    {
        std::cout &lt;&lt; parser-&gt;getError(i)-&gt;desc() &lt;&lt; std::endl;
    }

    builder-&gt;setMaxBatchSize(maxBatchSize);
    nvinfer1::IBuilderConfig* config = builder-&gt;createBuilderConfig();
    config-&gt;setMaxWorkspaceSize(1 &lt;&lt; 20);
    nvinfer1::ICudaEngine* engine = builder-&gt;buildEngineWithConfig(*network, *config);

    parser-&gt;destroy();
    network-&gt;destroy();
    config-&gt;destroy();
    builder-&gt;destroy();

    nvinfer1::IHostMemory *serializedModel = engine-&gt;serialize();

    std::ofstream engine_file(&quot;saved_resnext.engine&quot;);

    engine_file.write((const char*)serializedModel-&gt;data(),serializedModel-&gt;size());

    serializedModel-&gt;destroy();
    return 0;
 }

While compiling, I get the following error:
/tmp/ccJaGxCX.o: In function `nvinfer1::(anonymous namespace)::createInferBuilder(nvinfer1::ILogger&amp;)':
rnxt.cpp:(.text+0x19): undefined reference to `createInferBuilder_INTERNAL'
/tmp/ccJaGxCX.o: In function `nvonnxparser::(anonymous namespace)::createParser(nvinfer1::INetworkDefinition&amp;, nvinfer1::ILogger&amp;)':
rnxt.cpp:(.text+0x43): undefined reference to `createNvOnnxParser_INTERNAL'
collect2: error: ld returned 1 exit status

I also get error related to &lt;cuda_runtime_api.h&gt; so I have added (pasted) those files from cuda's include directory (/usr/local/cuda-11.0/targets/x86_64-linux/include) to the /usr/include directoryafter which I am getting the said error. I don't have much experience with C++ and any help would be appreciated.
Edit: I have also installed libnvinfer using
!apt-get install -y libnvinfer7=7.1.3-1+cuda11.0
!apt-get install -y libnvinfer-dev=7.1.3-1+cuda11.0


This problem is due to nvonnxparser.so  was not linked in Makefile. Just add
target_link_libraries(${TARGET_NAME} nvonnxparser)

in your CMake.
