Systemverilog dpi c: How to import more than one c files!?!

Hi all,
I’m trying to call c function inside a c dpi file. Compilation flow are doing well but when simulation call function a fatal error occur with:
** Fatal: (vsim-12005) Undefined function ‘globalb()’ introduced from ‘/tmp/***/linux_x86_64_gcc-5.3.0/vsim_auto_compile.so’ is being called. Exiting …
Here my files:

-------------my_sv_unit_dpi.sv --------------------

module my_sv_unit_dpi_inc; 

export "DPI-C" task rd_hw;
import "DPI-C" context task read_register();

  task rreg;
      read_register();
   endtask

  task  rd_hw(input int addr, output int data);
   #10;
   data = $urandom;
	$display("@%10t :  Read Done  [ADDR = %08h, DATA = %8h]", $time, 
                                addr , data);
    //#t = $stime;
  endtask : rd_hw
endmodule : my_sv_unit_dpi_inc


module my_sv_unit_dpi (output logic a, input logic clk); 
 
   my_sv_unit_dpi_inc prova();
 
      initial repeat(10)
	begin
	   prova.rreg;
  	   prova.read_register; // this works too - no wrapper needed
           #500; // read every 
	end
endmodule

-------------my_dpi.cc --------------------

#include <iostream>
#include "svdpi.h"
#include "my_dpi.h"
#include "../source-c/device.h"
using namespace std;

extern int rd_hw(int, int*); 
 
void init_a( void);

void init_a( void)
{
    int ret;
    int i, len;
    uint8_t a = 0;
    uint8_t part = 0;
  
    len = 10;
    for(i = 0; i < len; i++)
    {
        globalb();
        cout << "init_a i" << std::hex << i <<endl;

    }
}


int read_register(void)
{
  int status;
  int rddata;
  init_a();
  status = rd_hw(0x0, &rddata);
  cout << "(C++) Data is " << std::hex << rddata << endl;
  cout << "Scope is " << svGetNameFromScope(svGetScope()) << endl;
  return status;
}
--------------------------------------------------------
------------------device.h-------------------
int globalb();
void globalc();

--------------------------------------------------------

--------------------globalb.c--------------------------
#include "device.h"
#include <stdio.h>


int globalb(void)
{
  printf("whe are into globalb body");
    globalc();
    return 0;
}



--------------------------------------------------------

--------------------globalc.c--------------------------
#include <stdio.h>
#include "device.h"


void globalc(void)
{
  printf("whe are into globalc body");
}

compilation flow
gcc -shared -fPIC -lm -Bsymbolic -o mylibc.so globalb.c globalc.c
vlog -64 my_sv_unit.sv
vlog -64 my_sv_unit_dpi.sv my_dpi.cc -dpiheader my_dpi.h

Where I’m wrong here?
Thanks
Regards

In reply to andleon82:

The error that you showed means, function globalb was not found. You compiled the shared library

gcc -shared -fPIC -lm -Bsymbolic -o mylibc.so globalb.c globalc.c

But did you load the mylibc.so file when running?

In reply to andleon82:

Normally you can put all your C/C++ files on the command line with your SystemVerilog files. But this Mentor sponsored public forum is not for discussing tool specific issues. Please read your tool’s User Manual, or contact your tool vendor for support.

In reply to dave_59:

Alternatively, you can compile all C/C++ files to shared library file (.so) then load it to vsim command using -sv_lib.

In reply to cuonghle:

Hi Chris Le,
of course I load mylibc.so with -sv_lib mylibc with vsim and I can see the correct loaded library during loading phase of simulator.
Thanks

In reply to dave_59:

Hi Dave,
I’d already checked into the manual but I couldn’t find any similar examples into Manual or inside example directory of mentor installation.
I would like to find an example template with more than 1 c file.
Thanks
Regards

In reply to andleon82:

One more thing you should notice.
You should compile shared library .so using gcc with option -m64 (64 bits) to match with vlog -64 command, otherwise the shared library could not be loaded correctly.

gcc -m64 -shared -fPIC -lm -Bsymbolic -o mylibc.so globalb.c globalc.c

In reply to cuonghle:

Same behaviour with -m64

In reply to andleon82:

You can use the following ways:

  1. Either put all source C files in vlog command, example:

vlog -64 my_sv_unit_dpi.sv  globalb.c globalc.c my_dpi.cc -dpiheader my_dpi.h

  1. Or you can compile all source C files to shared library .so, then load it in vsim command (remember add -m64 to be compatible with vsim/vlog -64 command), example:

gcc -m64 -shared -fPIC -lm -Bsymbolic -o mylibc.so globalb.c globalc.c my_dpi.cc
vsim -64 -c -do "run -a;q" <top> -sv_lib mylibc