`包含在系统Verilog中的函数定义中

`包含在系统Verilog中的函数定义中,verilog,system-verilog,Verilog,System Verilog,我有一个简单的系统Verilog代码,其中包含一个包含很少函数定义的文件。然而,当我有多个文件,其中包括这个文件,然后我得到编译错误,由于函数重新定义。对如何解决这个问题有什么建议吗 代码test.sv: `include "constants.sv" module test(); real myReal1; real myReal2; initial myReal1 = 10.1; assign myReal2 = abs(myReal1); endmodule 代码:test2.

我有一个简单的系统Verilog代码,其中包含一个包含很少函数定义的文件。然而,当我有多个文件,其中包括这个文件,然后我得到编译错误,由于函数重新定义。对如何解决这个问题有什么建议吗

代码test.sv:

`include "constants.sv"

module test();

real myReal1;
real myReal2;

initial myReal1 = 10.1;

assign myReal2 = abs(myReal1);

endmodule
代码:test2.sv:

`include "constants.sv"

module test2();

real myReal1;
real myReal2;

initial myReal1 = 10.1;

assign myReal2 = 10.2;

endmodule
错误:

function real abs(input real a);
                |
ncvlog: *E,DUPIDN (./constants.sv,19|16): identifier 'abs' previously declared [12.5(IEEE)].

尽可能使用软件包或使用include guard避免碰撞

快速解决方案:

`ifndef CONSTANTS
   `define CONSTANTS
   `include "constants.sv"
`endif  

以下是对我有效的方法: 文件constants.sv的内容:

`ifndef SVINCLUDES

   //define all macros here
   //define all functions here

   `define SVINCLUDES

`endif

您所指的包含指南是什么?类似于
`ifndef xxx\n`define xxx\n`endif
ifndef仅适用于文本宏。在这里,如果函数尚未定义,我想使用` include语句。我不知道如何使用ifndefThanks来实现这一点,这就是我最终所做的,并且它起到了作用!