Compilation Issue from define in package

Hi

Iam using Questasim10.0d.

when i run a particular code iam getting below error:

QuestaSim-64 vlog 10.1a Compiler 2012.02 Feb 21 2012
– Compiling package common_pkg
** Error: ui_transaction.sv(5): (vlog-2163) Macro `ADDR_WIDTH is undefined.

I have code below:

//ui_transaction.sv
import common_pkg::*;
class ui_transaction;
 rand bit [`ADDR_WIDTH-1:0] addr;
endclass: ui_transaction

module tb_top();
  initial begin
    $display("Hello");
  end
endmodule
//common_pkg.sv
package common_pkg;
 `define ADDR_WIDTH 20
endpackage

Thanks
Bharath

Compiler directives do not belong to any scopes. The are preprocessed before compilation. Use a parameter or typedef instead.

parameter ADDR_WIDTH = 20;
typedef bit [19:0] ADDR_t;

Bharath,
Few notes:

  1. Your Questa version is old, see if you can move to 10.2 or later. There -mfcu (read below) is default.
  2. I assume you compile common_pkg.sv before the ui_*.sv file
  3. Now, yes Dave is correct (as usual), `define-s don’t get scoped, so no real value in adding them inside package.
  4. Now in old versions Questa needed a -mfcu flag to carry the `defines across files. Read your manual or better yet “read #1 above” :-)

So you may be able to get going with -mfcu added to vlog command.

Ajeetha, CVC

In reply to ajeetha:

Thanks Ajeetha,

with the flag -mfcu passed the issue resolved and compilation issue is been fixed.

Thanks
Bharath

In reply to bhartahece:

BTW, I don’t recommend using the -mfcu switch - it makes it hard to break up your compilation into units that can be organized and compiled separately, forcing you to always compile your entire design in a single step. So called “incremental compile” features can save some time, but the compiler still has to access all your files to see what has changed.

For this issue, I think it would be really good to refer Dave’s post:
http://go.mentor.com/package-import-versus-include

So, here once you define something in a package it is different than including a define directly. So compiler could not look for define macro which is defined inside the package. Please note the difference between referring something from package and using compiler define directives.

Regards,
Parthav