How To: Integrate C/C++ Files with Your Design
Given a C file my_project/src/my_dpi_code.c or C++ file my_project/src/my_dpi_code.cpp, you can integrate it with your HDL design by passing it to DSim Cloud to compile and link into the generated image.
1. Modify my_dpi_code.cpp to prefix each DPI function with extern "C"
. For example:
extern "C" int byte_cfunc(const svOpenArrayHandle data) { return svDimensions(data); } extern "C" int bit_cfunc(const svOpenArrayHandle data) { return svDimensions(data); } extern "C" int bit2_cfunc(const svOpenArrayHandle data) { return svDimensions(data); }
Henceforth, my_dpi_code.cpp and my_dpi_code.c are used interchangeably.
2. Append my_dpi_code.c or my_dpi_code.cpp to your DSim elaboration command with compiler options:
my_project> mdc dsim -a '-genimage myimage -F filelist.txt -top my_test -timescale 1ns/1ps +acc+b src/my_dpi_code.cpp -c-opts "<compiler options>"'
3. Confirm the compilation of my_dpi_code.cpp by observing the following message in your terminal:
=N:[C/C++] Compiled file src/my_dpi_code.cpp
4. If your C/C++ code requires a system library, add -sv_lib
to your DSim run command to load the library from the system:
my_project> mdc dsim -a '-image myimage -waves waves.mxd -sv_lib lib<library name>.so'
For more information, see the C Language Support section of User Guide: DSim Common Options.