1

ModelSim User's manual (v10.1c), in page 660, talks about the default autocompile flow (using vlog) and external compilation flow to get the the DPI-C to work in ModelSim. I'm able to get the auto-compile flow to work. I'm stuck with the external compilation flow.

Problem Summary: I get an "undefined reference" error in when I try to create the .dll file in-spite of using the right export and import statements in my system verilog file.

Here are the files that make up this project:

file 1: mytest.cpp

#include<stdio.h>
#include "experiment3.h"

int mymain() {
   printf("---starting test in c-domain---\n");
   PrintHelloWorld();
   return 0;
}

file 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

file 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

Here are the command that I am using:

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

Most of the online DPI-C examples deal with running (CPP and .SV) everything in ModelSim. I don't want that. I want to keep the HW and SW flow separate. And, this separation does work to some extent (I have no issues with calling C functions from SV (import works fine). The roadblock is with trying to call SystemVerilog function from the C function (something seems to be wrong with the export).

Any thoughts on how I can get past this hurdle ?

4

2 回答 2

0

尝试改变

DPI_LINK_DECL void
PrintHelloWorld();

DPI_LINK_DECL DPI_DLLISPEC void
PrintHelloWorld();

(如果 DPI_DLLISPEC 不起作用,直接用 替换它__declspec(dllimport)

于 2019-11-07T13:11:22.990 回答
0

根据查看示例,尝试添加-fPIC到您的命令 1。然后命令 2 应该按原样工作。

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

于 2019-11-06T01:22:56.027 回答