Import Example Using -sv_lib, -sv_liblist, and -sv_root - 2022.1 English

Vivado Design Suite User Guide: Logic Simulation (UG900)

Document ID
Release Date
2022.1 English


Assume that there are:

  • Two files each containing a C function
  • A SystemVerilog file that uses the following functions:
    • function1.c
    • function2.c


#include "svdpi.h"
int myFunction1()
    return 5;


#include <svdpi.h>
int myFunction2()
    return 10;

module m();
import "DPI-C" pure function int myFunction1 (); 
import "DPI-C" pure function int myFunction2 ();
integer i, j;
  i = myFunction1();
  j = myFunction2();
  $display(i, j);
  if( i == 5 && j == 10)


Methods for compiling and linking the C files into the Vivado simulator are described below.

Single-step flow (simplest flow)

xsc function1.c function2.c
xelab -svlog -sv_lib dpi

Flow description:

The xsc compiler compiles and links the C code to create the shared library xsim.dir/xsc/, and xelab references the shared library through the switch -sv_lib.

Two-step flow

xsc -compile function1.c function2.c -work abc
xsc -shared/-shared_systemc abc/function1.lnx64.o abc/function2.lnx64.o -work abc 
xelab -svlog -sv_root abc -sv_lib dpi -R

Flow description:

  • Compile the two C files into corresponding object code in the work directory abc.
  • Link these two files together to create the shared library
  • Make sure that this library is picked up from the work library abc via the -sv_root switch.
    Tip: -sv_root specifies where to look for the shared library specified through the switch -sv_lib. On Linux, if -sv_root is not specified and the DPI library is named with the prefix lib and the suffix .so, then use the LD_LIBRARY_PATH environment variable for the location of shared library.

Two-step flow (same as above with few extra options)

xsc -compile function1.c function2.c -work "abc" -v 1
xsc -shared/-shared_systemc "abc/function1.lnx64.o" "abc/function2.lnx64.o" -work "abc" -o final -v 1 
xelab -svlog -sv_root "abc" -sv_lib final -R

Flow description:

If you want to do your own compilation and linking, you can use the -verbose switch to see the path and the options with which the compiler was invoked. You can then tailor those to suit your needs. In the example above, a distinct shared library final is created. This example also demonstrates how spaces in file path work.