Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass data between SV and C++ bidirectionally via open array with DPI import function

My goal is to fill an open array by C++. The stage is as follows. 1. SV: Define a sized unpacked array and send it via open array in the import function. 2. C++: Fill the open array. 3. SV: Use the array.

For the sized unpacked array, there is no problem. But in real situation the array size is changed often and the compiled C++ function must be recompiled each time. To avoid this situation, I need to use an open array so that the C function check the size and fill the data accordingly.

In the following, the sources are simplified showing only the essential parts. The import function svcpp called at SV and executed in C++. The arguments are the open array i[], whose handle is h in C++ side. When I compile the C++ source, the error occurs, "error LNK1120: unresolved externals".

What is the problem?

SV side:

module
    import "DPI-C" context function void svcpp (inout byte unsigned i[]);
    byte myarray[2];

    initial
        svcpp(myarray);
endmodule

C++ side:

#include "svdpi.h"
#include "dpiheader.h"// This includes the data structure for the open array

void svcpp(const svOpenArrayHandle h){
    //*(uchar *) x = *(uchar *) svGetArrElemPtr(h,0);
    *(uchar *) svGetArrElemPtr(h,1) = 10; //I really want this operation.
}
like image 968
gnoejh Avatar asked Nov 10 '22 04:11

gnoejh


1 Answers

You might try this to avoid the C++ compiler from mangling the name of your function.

extern "C" void svcpp(const svOpenArrayHandle h) {
 ...
}
like image 147
jclin Avatar answered Nov 15 '22 08:11

jclin