Clarification on using OpenACC in a shared library

I read other threads on the forum and they give quite useful information:

It seems like shared library + nordc + global/static variables is no go! Here is modified example from previous that compiles but the pointers on device are NULL. This is quite confusing :

float* my_data;
#pragma acc declare create(my_data)

void init(double val) {
    my_data = (float*) malloc(sizeof(float)*3);
    my_data[0] = 1.1;
    #pragma acc enter data create(my_data[0:3])
}

#pragma acc routine seq
void print() {
    printf("--> data %p\n", my_data);
}

void sample() {
  #pragma acc parallel loop
  for(int i=0; i<3; i++)
  {
        print();
  }
}

and compiling & running fives:

+ pgc++ -acc -ta=tesla:nordc -Minfo ext.cpp -c -fPIC
y_square():
      2, Generating acc routine seq
         Generating Tesla code
+ pgc++ -acc -ta=tesla:nordc -Minfo test.cpp -c -fPIC
init(double):
     11, Generating enter data create(my_data[:3])
print():
     14, Generating acc routine seq
         Generating Tesla code
sample():
     18, Generating Tesla code
         20, #pragma acc loop gang, vector(3) /* blockIdx.x threadIdx.x */
+ pgc++ -acc -ta=tesla:nordc -shared -o test.so test.o
+ pgc++ -acc -ta=tesla:nordc main.cpp test.so
main.cpp:
+ ./a.out
--> data (nil)
--> data (nil)
--> data (nil)

my_data being nil?

(The shared library aspects are quite important for the application. Also, it’s difficult to change global/static variables + routine seq due to legacy DSL layer)

If I have global variables like above, is there any other way (even convoluted) to get this working?