【问题标题】:DPI-C and SystemVerilog External Compilation flow issueDPI-C 和 SystemVerilog 外部编译流程问题
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

    • 我试过了。没运气。 ModelSim User's manual提到它是基于unix的系统的.so和基于windows的系统的.dll。
    • 我将文件移动到基​​于 unix 的系统中,我可以轻松通过这两个步骤。对于基于 Windows 的机器,可能创建 .dll 的过程是不同的......
    【解决方案2】:

    尝试改变

    DPI_LINK_DECL void
    PrintHelloWorld();
    

    DPI_LINK_DECL DPI_DLLISPEC void
    PrintHelloWorld();
    

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

    【讨论】:

    • 不起作用。我收到以下错误:c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: ./mytest. o:mytest.cpp:(.text+0x2d): undefined reference to `_imp__PrintHelloWorld'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2010-11-26
    相关资源
    最近更新 更多