Save picture on jetson, got error undefined reference to `NvBufSurfaceMap' NvBufSurfaceSyncForDevice,NvBufSurfaceUnMap

on jetson AGX orin
my error:
/usr/bin/ld: CMakeFiles/ds_app_multi_input_output.dir/ds_app_multi_input_output.cpp.o: in function osd_sink_pad_buffer_probe(_GstPad*, _GstPadProbeInfo*, void*)': /app/ds_tracker_paul3090/ds_app_multi_input_output.cpp:165: undefined reference to NvBufSurfaceMap’
/usr/bin/ld: /app/ds_tracker_paul3090/ds_app_multi_input_output.cpp:178: undefined reference to NvBufSurfaceSyncForDevice' /usr/bin/ld: /app/ds_tracker_paul3090/ds_app_multi_input_output.cpp:179: undefined reference to NvBufSurfaceUnMap’
part of code:
NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
NvBufSurfacePlaneParams pParams = &surface->surfaceList[frame_meta->batch_id].planeParams;
unsigned int offset = 0;
for(unsigned int num_planes=0; num_planes < pParams->num_planes; num_planes++){
offset += pParams->height[num_planes-1]
for (unsigned int h = 0; h < pParams->height[num_planes]; h++) {
memcpy((void )(src_data+offset+hpParams->bytesPerPix[num_planes]*pParams->width[num_planes]),
(void *)((char )surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[num_planes]+hpParams->pitch[num_planes]),
NvBufSurfaceSyncForDevice (surface, -1, -1);
NvBufSurfaceUnMap (surface, -1, -1);
gint frame_width = (gint)surface->surfaceList[frame_meta->batch_id].width;
gint frame_height = (gint)surface->surfaceList[frame_meta->batch_id].height;
gint frame_step = surface->surfaceList[frame_meta->batch_id].pitch;
cv::Mat frame = cv::Mat(frame_height, frame_width, CV_8UC4, src_data, frame_step);
// g_print(“%d\n”,frame.channels());
// g_print(“%d\n”,frame.rows);
// g_print(“%d\n”,frame.cols);

    cv::Mat out_mat = cv::Mat (cv::Size(frame_width, frame_height), CV_8UC3);
    cv::cvtColor(frame, out_mat, COLOR_RGBA2BGR);
    snprintf (fileNameString, FILE_NAME_SIZE, "%d_%d.jpg",
      frame_meta->source_id, frame_number);
    cv::imwrite(fileNameString, out_mat);

Can you format the code better and give a lot more details about what you are doing and what you are using.
Also, undefined reference usually means linker problems.
How you created this code by yourself? If yes then correct your Makefile.
for example incase of nvbuf, add this to your Makefile.
-L/opt/nvidia/deepstream/deepstream/lib -lnvbufsurface -lnvbufsurftransform along with other dependencies.

Like I mentioned earlier, sorry but you need to give a lot more details for anyone to understand your problem.

This my cmakelist.txt file.

Yes so your nvbufsurface is not being linked since you have not linked its libraries.

nvbufsurface and nvbufsurftransform.

Can you try adding this?

i link this libraries, and no error appeared . thank you

1 Like


i add the nvbufsurface to target_link_libraries, and this problem is resloved. and i want to know that is nvbufsurface library? i always think it is .h file.

.h files are header files.
You also need to link the libraries using the .so files.

run this command and you will see both, nvbufsurface.h and
sudo find / | grep nvbufsurface

Now why do you need both, header files and linker files, you will find better answers on the internet or by other members in the forum that me.

But for example:
a.cpp is a code which uses opencv4
when you compile add.cpp with .h header files, it created an object file called add.o.

then you run it link it with dependencies/libraries with .so files which are shared object files which ultimately created the executable which we run using ./a.out.

You yourself have been using linker file for opencv $(OpenCV_LIBS)

pkg-config opencv4 --cflags --libs where cflags are header files and libs are the linker files.

Thank you for your answer.
May I ask another question. How to add the whole deepstream lib instead of adding nvbufsurface, nvds_meta one by one.

I am really not sure since I am not that great with cmakelists.
I think some other members can help you with this.
What I can suggest is, try asking this question in a linux/ubuntu forums or stackoverflow. Thanks.

Thank you so so much.

1 Like

Is this topic the same to the 276723?

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