NULL FOREIGN FUNCTION POINTER ENCOUNTERED

I am using dpi to invoke c function in my systemVerilog environment.
For the following code

import “DPI-C” encoder=function void encoder(byte input_buf[3000],byte parity[500]);
.
.
.
.
encoder(input_buf, parity); //calling the function

If the File in which function encoder(…,…) is present is a cfile(.c) then simulation works well.
But if that file is c++file(.cpp) then it gives a fatal error saying null foreign function pointer encountered while calling encoder.

function is defined as…

void encoder( unsigned char *input_buf , unsigned char *parity)
{
.
.
.
}

Can anyone help me with this

In reply to ganesh shetti:

note: include "“svdpi.h” is included

In reply to ganesh shetti:

DPI functionality expects that the compiled C functions support ‘C’ linkage. Since C++ uses function overloading, it will ‘mangle’ the function names, making them incompatible with standard C linking.

You need to preface your function declaration with ‘extern “C”’ to tell the C++ compiler/linker to not mangle the function name.

Most modern SystemVerilog simulators will generate the appropriate C/C++ header file for your DPI functions. Please refer to your user manual and use this feature if available instead of trying to write your own header file.