Data sharing between lib gstdsexample and deepstream_app_main.c

I am using deepstream_app for my object detection.

I do some processing for detected boxes in gst-dsexample.cpp.
gst-dsexample is plugin to deepstream_app at the last stage.
So if I want to highlight with different color using obj->rect_params, the color is not updated in display.

So I need to share globaldata between the two source files, gstdsexample.cpp and deepstream_app_main.c
The globaldata is bounding box id (identified by my customized identification code in gstdsexample.cpp) and will be shared to deepstream_app_main.c to highlight with different color using obj->rect_params in all_bbox_generated() inside deepstream_app_main.c.

What I did was

sharedata.h (global variables pointerto hold BBOx id)

#ifndef __SHARE_DATA_H__
#define __SHARE_DATA_H__
#include <stdio.h>
#include <pthread.h>

#ifdef __cplusplus
extern "C" {
#endif

// declare your two vars in the header file as extern. 
extern pthread_mutex_t mutex;
extern int *ptr;


#ifdef __cplusplus
}
#endif

#endif /* __SHARE_DATA_H__ */

deepstream_app_main.c has malloc and reading data from pointer.


#include "sharedata.h"
int all_bbox_generated(){
 pthread_mutex_lock( &mutex ); 
  for (int x = 0; x < 5; x++)
  {     
    printf("%d ", *(ptr+x));         
  }
  printf("\n");
  pthread_mutex_unlock( &mutex ); 
}

int main(){
  pthread_mutex_lock( &mutex );
  ptr = (int *)malloc((4 * 5) * sizeof(int)); 
  pthread_mutex_unlock( &mutex );

 
}

Inside gstdsexample.cpp,

#include "sharedata.h"
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int *ptr;

{
   printf("before lock\n");
   pthread_mutex_lock( &mutex ); 
   for (int x = 0; x < 5; x++)
   {     
      printf("before pointer\n");
      *(ptr+x) = 1;      
   }
   pthread_mutex_unlock( &mutex ); 

}

I can compile and build libgstdsexample.

But I have undefined reference error for ptr and mutex in compilation at deepstrea-app.

How can I solve?

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
• DeepStream Version
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs)
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

• Hardware Platform (Jetson / GPU)
Xavier
• DeepStream Version
5.1 (latest)
• JetPack Version (valid for Jetson only)
R32 (release), REVISION: 4.3, GCID: 21589087, BOARD: t186ref, EABI: aarch64, DATE: Fri Jun 26 04:34:27 UTC 2020
• TensorRT Version
latest
• NVIDIA GPU Driver Version (valid for GPU only)
10.2
Can reproduce using gstdsexample.cpp, deepstream_app_main.c and

sharedata.h
#ifndef __SHARE_DATA_H__
#define __SHARE_DATA_H__
#include <stdio.h>
#include <pthread.h>

#ifdef __cplusplus
extern "C" {
#endif

// declare your two vars in the header file as extern. 
extern pthread_mutex_t mutex;
extern int *ptr;


#ifdef __cplusplus
}
#endif

#endif /* __SHARE_DATA_H__ */

I know sharing global variables is not a good practice.
For my requirement, what could be good approach?

My main project is deepstream-app.

I am doing my own illegal parking detection using Bboxes in gstdsexample.cpp.

Once those boxes are identified, I need to highlight on display.
Since gstdsexample is plugged in from last stage in deepstream-app,
Changing the color of box to highlight using obj->rect_params doesn’t change color of box on actual display.

So in that case, how can I do to change color of box in display?