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.
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.
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)
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)
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.