【发布时间】:2019-11-05 19:42:54
【问题描述】:
ModelSim 用户手册 (v10.1c),在第 660 页,讨论了默认的自动编译流程(使用 vlog)和外部编译流程,以使 DPI-C 在 ModelSim 中工作。我能够让自动编译流程工作。我坚持使用外部编译流程。
问题摘要:当我尝试创建 .dll 文件时出现“未定义引用”错误,尽管在我的系统 verilog 文件中使用了正确的导出和导入语句。 p>
以下是构成该项目的文件:
文件 1: mytest.cpp
#include<stdio.h>
#include "experiment3.h"
int mymain() {
printf("---starting test in c-domain---\n");
PrintHelloWorld();
return 0;
}
文件 2:experiment3.h
#ifndef INCLUDED_EXPERIMENT3
#define INCLUDED_EXPERIMENT3
#ifdef __cplusplus
#define DPI_LINK_DECL extern "C"
#else
#define DPI_LINK_DECL
#endif
#include "svdpi.h"
DPI_LINK_DECL DPI_DLLESPEC
int
mymain();
DPI_LINK_DECL void
PrintHelloWorld();
#endif
文件 3: mytb.sv
module mytb;
timeunit 1ns/1ps;
export "DPI-C" function PrintHelloWorld;
import "DPI-C" context task mymain();
function void PrintHelloWorld();
$display("HelloWorld\n");
endfunction
//start test
initial begin
#10ns;
mymain();
end
endmodule
这是我正在使用的命令:
command 1 :g++ -c -IC:\intelFPGA\17.0\modelsim_ase\include -o ./mytest.o ./mytest.cpp
comments :command 1 executes without any problem
key-words :MinGW, GCC
command 2 :g++ -shared -Bsymbolic -o ./mytest.dll ./mytest.o -LC:\intelFPGA\17.0\modelsim_ase\win32aloem
comments :[1] command 2 fails when I use the mytest.cpp showed above
[2] command 2 passes when I comment out "PrintHelloWorld()" in mytest.cpp
error :c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe:
./mytest.o:mytest.cpp:(.text+0x2d): undefined
reference to '`PrintHelloWorld' collect2.exe:error:ld
returned 1 exit status
key-words :MinGW, GCC, dll
command 3 : vsim -sv_lib ../src_cpp/mytest work.mytb
comments : [1] executed in console in ModelSim
[2] works when I don't have "PrintHelloWorld()" in mytest.cpp
大多数在线 DPI-C 示例都涉及在 ModelSim 中运行(CPP 和 .SV)所有内容。我不想要那个。我想保持硬件和软件流分开。而且,这种分离在某种程度上确实有效(我从 SV 调用 C 函数没有问题(导入工作正常)。障碍是尝试从 C 函数调用 SystemVerilog 函数(导出似乎有问题)。
关于如何克服这个障碍有什么想法吗?
【问题讨论】:
标签: gcc system-verilog modelsim system-verilog-dpi