# Custom Gstreamer plugin could not find CUDA Driver API function

**URL:** <https://forums.developer.nvidia.com/t/custom-gstreamer-plugin-could-not-find-cuda-driver-api-function/120126>\
**Category:** Jetson Nano\
**Tags:** gstreamer, cuda\
**Created:** [April 17, 2020, 11:09am UTC](https://forums.developer.nvidia.com/t/custom-gstreamer-plugin-could-not-find-cuda-driver-api-function/120126 "2020-04-17T11:09:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rus8](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rus8/32/16560_2.png) [@rus8](https://forums.developer.nvidia.com/u/rus8)\
**Post date:** [April 17, 2020, 11:09am UTC](https://forums.developer.nvidia.com/t/custom-gstreamer-plugin-could-not-find-cuda-driver-api-function/120126/1 "2020-04-17T11:09:35Z")

</div>

Hi,  
My custom plugin is based on ds-example. I am trying to use EGL-CUDA interoperability to apply my CUDA kernel to an image. Following hints in ds-eample source code I am using CUDA driver API to map data:

```auto
if (NvBufSurfaceMapEglImage (&ip_surf, 0) !=0 ) goto error; 

CUgraphicsResource *pCudaResource;
CUeglFrame *pEglFrame;

if (cuGraphicsEGLRegisterImage(pCudaResource,
           ip_surf.surfaceList[0].mappedAddr.eglImage,
           CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE)
           != CUDA_SUCCESS) {
                GST_ERROR("Could n't register EGL image.");
                goto error;
}
if (cuGraphicsResourceGetMappedEglFrame(pEglFrame, *pCudaResource, 0, 0) 
           != CUDA_SUCCESS) {
                GST_ERROR("Could n't get cuda EGL frame.");
                goto error;
}

```

I use cmake to build plugin:

```auto
cuda_add_library(gstdsmyplugin SHARED gstdsmyplugin.cpp)
target_include_directories(gstdsmyplugin PUBLIC
        ${OpenCV_INCLUDE_DIRS}
        ${GST_INCLUDE_DIRS}
        ${DEEPSTREAM_INCLUDE_DIRS}
        ${CUDA_INCLUDE_DIRS}
        )
target_link_libraries(gstdsmyplugin
        frameproc # a lib with my CUDA kernel
        ${OpenCV_LIBS}
        ${GST_LIBRARIES}
        ${DEEPSTREAM_LIBRARIES}
        ${CUDA_LIBRARIES}
        )

```

When I run my GStreamer app with the custom plugin the problem appears:

```auto
(gst-plugin-scanner:20047): GStreamer-WARNING **: 12:22:54.192: Failed to load plugin '/usr/lib/aarch64-linux-gnu/gstreamer-1.0/deepstream/libgstdsmyplugin.so': /usr/lib/aarch64-linux-gnu/gstreamer-1.0/deepstream/libgstdsmyplugin.so: undefined symbol: cuGraphicsEGLRegisterImage

```

My `LD_LIBRARY_PATH` contains CUDA libs directory:

```auto
user@dev-nano:~$ echo $LD_LIBRARY_PATH 
/usr/local/cuda/lib64

```

What lib contains the `cuGraphicsEGLRegisterImage` function?  
What am I doing wrong?

I will be grateful for any help :)

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [April 19, 2020, 10:53pm UTC](https://forums.developer.nvidia.com/t/custom-gstreamer-plugin-could-not-find-cuda-driver-api-function/120126/3 "2020-04-19T22:53:11Z")

</div>

Hi,  
These is a sample similar to your usecase. Please check

> [@How to create opencv gpumat from nvstream?](https://forums.developer.nvidia.com/t/how-to-create-opencv-gpumat-from-nvstream/70680/18):
>
> Hi, Please apply below code to get\_converted\_mat() in gstdsexample.cpp #include \<cudaEGL.h\> #include \<opencv2/cudafilters.hpp\> #ifdef \_\_aarch64\_\_ // To use the converted buffer in CUDA, create an EGLImage and then use // CUDA-EGL interop APIs if (USE\_EGLIMAGE) { if (NvBufSurfaceMapEglImage (dsexample-\>inter\_buf, 0) !=0 ) { goto error; } // dsexample-\>inter\_buf-\>surfaceList[0].mappedAddr.eglImage // Use interop APIs cuGraphicsEGLRegisterImage and // cuGraphicsR…

---

<div class="post-metadata">

**Author:** ![rus8](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rus8/32/16560_2.png) [@rus8](https://forums.developer.nvidia.com/u/rus8)\
**Post date:** [April 21, 2020, 1:33pm UTC](https://forums.developer.nvidia.com/t/custom-gstreamer-plugin-could-not-find-cuda-driver-api-function/120126/4 "2020-04-21T13:33:30Z")

</div>

Thank you for the answer!

I had to further study CUDA examples to find a solution.

The problem was in linking. It’s required to explicitly link `libcuda`, since it’s not placed in common CUDA libraries directory.

I added corresponding line in my `CMakeLists.txt`:

```auto
cuda_add_library(gstdsmyplugin SHARED gstdsmyplugin.cpp)
target_include_directories(gstdsmyplugin PUBLIC
        ${OpenCV_INCLUDE_DIRS}
        ${GST_INCLUDE_DIRS}
        ${DEEPSTREAM_INCLUDE_DIRS}
        ${CUDA_INCLUDE_DIRS}
        )
target_link_libraries(gstdsmyplugin
        frameproc # a lib with my CUDA kernel
        ${OpenCV_LIBS}
        ${GST_LIBRARIES}
        ${DEEPSTREAM_LIBRARIES}
        ${CUDA_LIBRARIES}
        cuda # <----- THIS LINE
        )

```

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 5:36pm UTC](https://forums.developer.nvidia.com/t/custom-gstreamer-plugin-could-not-find-cuda-driver-api-function/120126/6 "2021-10-18T17:36:52Z")

</div>


