DPI-C和SystemVerilog外部编译流程问题

ModelSim用户手册(v10.1c),在第660页中,讨论了默认的自动编译流程(使用vlog)和外部编译流程,以使DPI-C在ModelSim中工作。我能够使自动编译流程正常工作。我受制于外部编译流程。

问题摘要:尽管我在系统Verilog文件中使用了正确的导出和导入语句,但是在尝试创建.dll文件时,仍然收到“未定义引用”错误。 >

以下是组成该项目的文件:

文件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函数(导出似乎有些问题)。

关于我如何克服这一障碍的任何想法?

fluid120 回答:DPI-C和SystemVerilog外部编译流程问题

在查看示例的基础上,尝试将-fPIC添加到命令1中。然后命令2应该照常工作。

根据我的经验,最终文件应该是共享对象(.so);不是动态链接库(.dll)。我在基于Unix的系统上运行SystemVerilog,因此Windows可能有所不同。如果您遇到问题,可以尝试一下。

,

尝试更改

DPI_LINK_DECL void
PrintHelloWorld();

DPI_LINK_DECL DPI_DLLISPEC void
PrintHelloWorld();

(如果DPI_DLLISPEC无法正常工作,请直接用__declspec(dllimport)替换它)

本文链接:https://www.f2er.com/3156845.html

大家都在问