Usage of DPI-C in C programming

Hi all,

I have a question regarding the usage of DPI-C in the C-programming environment.

The problem I’m having a compiling issue where upon gcc compile, I get the following message in my terminal:

In file included from mytest.c:2:0:
vc_hdrs.h:9:19: fatal error: svdpi.h: No such file or directory
 #include <svdpi.h>
                   ^
compilation terminated.

The following are the lines of code that I am using:

testbench.sv

module test;

    export "DPI-C" function printf_output;        // sending the string_output task to c 

    function void printf_output();
        $display("Hello from SV");

    endfunction

endmodule

This is the c programming file that I am using to import the SystemVerilog functions: mytest.c

#include <stdio.h>
#include "vc_hdrs.h"

extern void printf_output();

int main() {
    printf("THIS IS THE C ENVIRONMENT");
    printf_output();

    return 1; 
}

When I compiled my SystemVerilog file with VCS, it generated a header file: vc_hdrs.h

#ifndef _VC_HDRS_H
#define _VC_HDRS_H

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <dlfcn.h>
#include <svdpi.h>


#ifdef __cplusplus
extern "C" {
#endif

#ifndef _VC_TYPES_
#define _VC_TYPES_
/* common definitions shared with DirectC.h */

typedef unsigned int U;
typedef unsigned char UB;
typedef unsigned char scalar;
typedef struct { U c; U d;} vec32;

#define scalar_0 0
#define scalar_1 1
#define scalar_z 2
#define scalar_x 3

extern long long int ConvUP2LLI(U* a);
extern void ConvLLI2UP(long long int a1, U* a2);
extern long long int GetLLIresult();
extern void StoreLLIresult(const unsigned int* data);
typedef struct VeriC_Descriptor *vc_handle;

#ifndef SV_3_COMPATIBILITY
#define SV_STRING const char*
#else
#define SV_STRING char*
#endif

#endif /* _VC_TYPES_ */


 extern void printf_output();

#ifdef __cplusplus
}
#endif


#endif //#ifndef _VC_HDRS_H

Is there something I have to change in the lines of my code to resolve this fatal error issue upon gcc compile on the c files? Any help would be appreciated.

Thanks!

Sangwoo Kim

Most simulators will have the file svdpi.h as part of their installation. You need to find it and add the include path to your gcc command.