DPI C++ Exports

Hi all,

I’ve been practicing with the DPI calls and was able to take full advantage of the DPI Import call. However, the DPI export does not seem to work for me. My code essentially looks like this:

// in SV
package my_dpi_pkg;
task get_value(input int idx, output longint data);
data = a[idx];
endtask : get_value

export “DPI-C” task get_value;

endpackage

// in C++, my_model.h
extern void get_value(int idx, long long *data)

// in C++, my_model.cc
void my_model::do_something() {

get_value(0, data);
}

However, when the C++ files compile to .o files, I get the error message, “undefined reference to get_value(…”

Any ideas on why I am seeing this error?

Thanks!!!
Billy

For C++, you need to do
[cpp]extern “C” get_value(
int idx,
int64_t* data);[/cpp]

If you you are using Questa, you should generate this header file from your SV code directly using the switch -dpiheader file.h. That way you can be sure at compile time that your arguments across the DPI match up.

One other tip about using DPI exports, make sure you use only SV tasks when your call might consume time, otherwise use stick with SV functions. There is some extra work to deal with process control if your process gets terminated.

In reply to dave_59:

For C++, you need to do
[cpp]extern “C” get_value(
int idx,
int64_t* data);[/cpp]
If you you are using Questa, you should generate this header file from your SV code directly using the switch -dpiheader file.h. That way you can be sure at compile time that your arguments across the DPI match up.
One other tip about using DPI exports, make sure you use only SV tasks when your call might consume time, otherwise use stick with SV functions. There is some extra work to deal with process control if your process gets terminated.

I have a question regarding this
**can we use in this way : ( because in one of my architechre implementation is like this. )

in C++ file
extern “C” {
void function_name(arg1,argu2);
}

and what is exactly meant static svScope and others(GetScopefromName,.etc) which are required to mention to work DPI.**

In reply to DEGALA BALAJI:
I have seen function prototypes with argument types and no names, but never names and no types. You need at least the types.

The scope information depends on what you are trying to do with the DPI. I think you should search the LRM and for online examples for those routines. I only have the time to answer very specific questions.