Importing a macro in a class

I am trying to import a macro in a class

The package code

package pkg;
`define CLOCK_WIDTH 20
endpackage

Driver code
task drive();

vif.reset = 1;
#(pkg::`CLOCK_WIDTH/2);
vif.reset = 0;

endtask :drive

But I am facing this error message

**Error-[UC] Unexpected character
The character ‘2’ is illegal in the context.
“driver.sv”, 73 (expanding macro)
Source info: #(pkg::`CLOCK_WIDTH/2);
**

How to resolve this one
NB: Package pkg is imported in top.sv before the compilation of driver.sv

In reply to bachan21:

A `define is a compile time directive and can’t be imported from a package.

Use a parameter instead.

In reply to cgales:

Sure cgales.
Thanks for the help

In reply to cgales:

but below code works fine

package my_pkg;
  `define CLOCK_PERIOD 10
endpackage 

module main;
   import my_pkg::*;

    initial begin
       $display("clock peripod = %0d",`CLOCK_PERIOD/2);
    end
endmodule

In reply to Desam:

That’s because the `define is being processed in the same file that it is being used in, so it is valid in this scope.

If you create two separate files and compile them separately, you will see a failure.

In reply to cgales:

sure…Thanks for clarification

In reply to Desam:

Note that if you had written

package my_pkg;
  `define CLOCK_PERIOD 10
endpackage 
 
module main; 
    initial begin
       $display("clock peripod = %0d",`CLOCK_PERIOD/2);
    end
endmodule

It still would have worked without the import. This is because macros get pre-processed and expanded before without any regard to SystemVerilog syntax.