how to run DPI in Modelsim

Status
Not open for further replies.

NGie

Newbie level 3
Joined
Nov 16, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
34
I usually run the DPI in command line using
gcc -I ./include -shared -m32 -o hello.so hello.c, then
vlog -sv hello.sv and finally
vsim -c hello -sv_lib hello -> run -all
Can I somehow write these commands into modelsim.ini to compile and run them directly? I've read that the sccom section does not support the -o parameter.
 

If you have a recent version of ModelSim, you can do
Code:
vlog hello.sv hello.c
vsim -c hello -do "run -all;quit"
This automatically compiles your DPI C code and creates a shared library that is automatically loaded by vsim.

A couple of other notes:

We do not recommend using the vlog -sv switch. This will treat any Verilog *.v file as SystemVerilog and you may get into trouble with reserved keywords. (reg logic; was fine in Verilog but now a syntax error in SystemVerilog).

We do recommend compiling DPI code with
Code:
vlog -dpiheader dpiheader.h hello.sv hello.c
and then in your DPI C file
Code:
#include "dpiheader.h"
This ensures that your SV task/function prototypes match your C routine prototypes. You will get a compile time error if they don't instead of a run time segmentation fault or some other weird behavior.
 
Reactions: NGie

    NGie

    Points: 2
    Helpful Answer Positive Rating
Thank you! It works! But... I have another stupid question. I've tried to set the path and wanted to compile the files from default directory. I tried some attempts, but I always got the error message:
vlog -dpiheader dpiheader.h hello.sv hello.c
QuestaSim-64 vlog 10.1b Compiler 2012.04 Apr 26 2012
** Error: (vlog-7) Failed to open design unit file "hello.sv" in read mode.
No such file or directory. (errno = ENOENT)
** Error: (vlog-19) Failed to access library 'work' at "work".
No such file or directory. (errno = ENOENT)
Questa has encountered an unexpected internal error: ../../../src/vcom/main.c(4135) cond. Please contact Questa support at **broken link removed**
** Fatal: (vlog-7005) Cannot create SystemVerilog DPI work directory ((null)/_dpi)
No such file or directory. (errno = ENOENT)

I probably forgot to change the path somewhere...
 

ModelSim does not use the shell search path; only the shell uses the search path. That's true for most programs. You need relative path names to all your files. (using -f filename will help)
 
Reactions: NGie

    NGie

    Points: 2
    Helpful Answer Positive Rating
I came back to my DPI example and tried to link an existing .so library. Can I use some vlog or vsim switch to define the path to the library?
Something like vlog -dpiheader dpiheader.h hello.sv hello.c -L <path>/libABC.so ?
Compilation results seem to be ok, but Modelsim run gives an error (unknown function, which is defined in the library and declared in a header file which has already been compiled)
 

So I should use qverilog instead of vlog and vsim commands? I tried to set the -ccflags switch for the vlog commands and it seems to be working.
But which command has the impact to the linker? Where to use the -ldflags switch?
 

I think -ccflags will take care of most options you need to deal with.

We recommend using vlog/vsim rather than qverilog. qverilog is for very simple flows. In fact we recommend multiple vlog commands to compile separate pieces of your code as independently as possible.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…