gpt4 book ai didi

c++ - 如何通过具有 DPI 导入功能的开放数组在 SV 和 C++ 之间双向传递数据

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:48:08 27 4
gpt4 key购买 nike

我的目标是用 C++ 填充一个开放数组。阶段如下。1. SV:定义一个大小的解包数组,并在导入函数中通过打开数组发送。2. C++:填充开放数组。3. SV:使用数组。

对于sized解包数组,没有问题。但在实际情况中,数组大小经常改变,编译后的 C++ 函数每次都必须重新编译。为避免这种情况,我需要使用开放数组,以便 C 函数检查大小并相应地填充数据。

在下文中,简化了来源,仅显示了基本部分。导入函数 svcpp 在 SV 调用并在 C++ 中执行。参数是开放数组 i[],其句柄在 C++ 端为 h。当我编译 C++ 源代码时,出现错误,“错误 LNK1120: Unresolved external 问题”。

问题是什么?

SV 侧:

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

initial
svcpp(myarray);
endmodule

C++ 方面:

#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.
}

最佳答案

您可以尝试这样做以避免 C++ 编译器破坏您的函数名称。

extern "C" void svcpp(const svOpenArrayHandle h) {
...
}

关于c++ - 如何通过具有 DPI 导入功能的开放数组在 SV 和 C++ 之间双向传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24913317/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com