# Package export does not work like I expect

**URL:** <https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [November 6, 2015, 8:05pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199 "2015-11-06T20:05:03Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![hawkeye](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/dc4da7/32.png) [@hawkeye](https://verificationacademy.com/forums/u/hawkeye)\
**Post date:** [November 6, 2015, 8:05pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/1 "2015-11-06T20:05:03Z")

</div>

I would like to export the contents of an imported package, particularly class definitions, but this doesn’t seem to work like I expect:

```verilog

package a_pkg;
  class a_class;
  endclass
endpackage

package b_pkg;
  import a_pkg::*;
//export a_pkg::a_class; // (1)
  export a_pkg::*; // (2)
endpackage

package c_pkg;
  import b_pkg::*;
  a_class a; // Compiles for (1), why doesn't it compile for (2)?
//a_pkg::a_class a; // Compiles for (1) and (2)
endpackage;

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 6, 2015, 9:02pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/2 "2015-11-06T21:02:27Z")

</div>

_In reply to [laarens](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199):_  
Because a wildcard import statement does not import everything in package a\_pkg; it only makes symbols candidates for importing.

The LRM says

> Symbols that are candidates for import but not actually imported are not made available.

The symbol a\_class must have a reference in b\_pkg to be exported.

```verilog
package b_pkg;
  import a_pkg::*;
  import a_pkg::a_class; // (1)
  export a_pkg::a_class; // (2)
  a_class a; // (3)  
  export a_pkg::*;       
endpackage

```

Any of the statements (1), (2), or (3) will cause a\_class to be exported.

---

<div class="post-metadata">

**Author:** ![hawkeye](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/dc4da7/32.png) [@hawkeye](https://verificationacademy.com/forums/u/hawkeye)\
**Post date:** [November 9, 2015, 1:33pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/3 "2015-11-09T13:33:37Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/2):_

Okay. Thanks for clarifying that for me.

---

<div class="post-metadata">

**Author:** ![user60](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user60/32/1096_2.png) [@user60](https://verificationacademy.com/forums/u/user60)\
**Post date:** [November 10, 2015, 10:27am UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/4 "2015-11-10T10:27:26Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/3):_

Dave,  
We had a similar requirement when trying to wrap UVM pkg into our own, custom package. Do you think it is reasonable to ask for an extension in the language for it? Consider:

package our\_uvm\_pkg;  
import uvm\_pkg::all; // Just a notion, for now it won’t work  
export uvm\_pkg::all; // Just a notion, for now it won’t work  
// More code, uses some of the uvm base classes, but not all  
endpackage : our\_uvm\_pkg

The benefit is user then has to import only “our\_uvm\_pkg” and gets all what’s provided by UVM.

Thanks  
Srini  
[http://www.verifworks.com](http://www.verifworks.com)

---

<div class="post-metadata">

**Author:** ![kiranag](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/k/5fc32e/32.png) [@kiranag](https://verificationacademy.com/forums/u/kiranag)\
**Post date:** [October 25, 2016, 6:39pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/5 "2016-10-25T18:39:00Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/4):_  
Hi dave\_59, could you please elaborate on what you mean by “candidate for importing” and “actually imported” objects?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [October 25, 2016, 9:24pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/6 "2016-10-25T21:24:35Z")

</div>

_In reply to [kiranag](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/5):_  
You have to look at the flow of source code to determine which symbols are candidate versus actually being imported. It can change over the span of a scope.

```verilog
package p1;
  int a,b,c,d;  
endpackage
package p2;
  int a;
  import p1::*; // the identifiers b,c, and d all become candidates for importing
                // 'a' is already declared in this local scope
  function f1;
     $display(b); // 'b' moves from being a candidate to actually imported. 
  endfunction 
  int c; // 'c' is no longer a candidate for importing
//int b; // this would be an error because 'b' was already imported. 
endpackage

```

So the   
import p1::\*; wildcard import statement actually imports only one symbol; ‘b’. This distinction becomes more important when you have the same symbol being a candidate for import coming from multiple packages. That’s OK until someone tries to actually import the symbol - which package do you import it from? It means you eithe rneed to make the symbol name unique in each package, or the intent was not to import the symbol by declaring locally beforehand.

---

<div class="post-metadata">

**Author:** ![dnguyen82us](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/ce73a5/32.png) [@dnguyen82us](https://verificationacademy.com/forums/u/dnguyen82us)\
**Post date:** [November 10, 2016, 7:55pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/7 "2016-11-10T19:55:14Z")

</div>

I follow this coding style putting all the files in a pkg.sv file but there is this compilation error. Not sure what caused this.

Error-[SE] Syntax error  
Following verilog source has syntax error :  
“project/verif/vkits/glbk/lbk\_pkg.sv”, 66: token is ‘endpackage’  
endpackage:lbk\_pkg  
^  
System verilog keyword ‘endpackage’ is not expected to be used in this  
context.

1 error

The file content is below.  
package lbk\_pkg;

//---------------------------------------------------------------------  
// Group: Imports  
import uvm\_pkg::\*;

// Forward class declarations to work around compile errors

typedef class config\_vseq\_c;  
typedef class reg\_comp\_rst\_vseq\_c;  
typedef class lbk\_sec\_reg\_walk\_seq\_c;  
typedef class lbk\_non\_sec\_reg\_walk\_seq\_c;  
typedef class lbk\_reg\_walk\_seq\_c;  
typedef class no\_op\_seq\_c;  
typedef class csr\_background\_read\_vseq\_c;  
typedef class env\_c;  
typedef class lbk\_p2x\_cfg\_c;  
typedef class lbk\_x2p\_cfg\_c;

//---------------------------------------------------------------------  
// Group: Includes  
// (`include package member files here, alphabetically.) `include “cvm\_pcc\_defs.vh”

`include "lbk_ecam_cfg_function.sv" `include “lbk\_types.sv”  
`include "lbk_cfg.sv" `include “lbk\_pkt\_cfg.sv”  
`include "lbk_pkt.sv" `include “lbk\_trans\_sb.sv”  
`include "lbk_chan_cred_sb.sv" `include “lbk\_perf\_sb.sv”  
`include "lbk_ebp_sb.sv" `include “lbk\_exer\_seq\_cfg.sv”  
`include "lbk_test_vseq_lib.sv" `include “lbk\_vsqr.sv”  
`include "lbk_config_vseq_lib.sv" `include “lbk\_env.sv”  
`include "lbk_p2x_cfg.sv" `include “lbk\_x2p\_cfg.sv”

endpackage : lbk\_pkg

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 10, 2016, 8:55pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/8 "2016-11-10T20:55:37Z")

</div>

_In reply to [dnguyen82us](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/7):_  
Usually when you get a syntax error from what seems like perfectly good code, it is because of the code just before it.

---

<div class="post-metadata">

**Author:** ![dhrogoff](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@dhrogoff](https://verificationacademy.com/forums/u/dhrogoff)\
**Post date:** [April 24, 2019, 4:27pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/9 "2019-04-24T16:27:44Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/8):_

> _In reply to [kiranag](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/8):_  
> You have to look at the flow of source code to determine which symbols are candidate versus actually being imported. It can change over the span of a scope.

```verilog
package p1;
int a,b,c,d;  
endpackage
package p2;
int a;
import p1::*; // the identifiers b,c, and d all become candidates for importing
// 'a' is already declared in this local scope
function f1;
$display(b); // 'b' moves from being a candidate to actually imported. 
endfunction 
int c; // 'c' is no longer a candidate for importing
//int b; // this would be an error because 'b' was already imported. 
endpackage

```

So the   
import p1::\*; wildcard import statement actually imports only one symbol; ‘b’. This distinction becomes more important when you have the same symbol being a candidate for import coming from multiple packages. That’s OK until someone tries to actually import the symbol - which package do you import it from? It means you eithe rneed to make the symbol name unique in each package, or the intent was not to import the symbol by declaring locally beforehand.

Dave, just to be 100% sure: In your example, if the last line of the package was   
export p1::_;__, then another module with   
import p2::_; would get   
p1::b. Correct? Therefore, export statements should be at the end of packages? This still is a big pain and not what’s expected. I agree with the suggestion of   
export XX::all; or similar. Do you know of any work on this in the 1800 committee?

Thanks,

David

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [April 24, 2019, 7:29pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/10 "2019-04-24T19:29:42Z")

</div>

_In reply to [dhrogoff](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/9):_

It doesn’t matter where the wildcard export statement is located in the package. Whatever was actually imported by the point of the endpackage gets exported.

The 1800 SystemVerilog committee has been dormant for the last 3 years. Vendors needed a chance to catch up after too many years of change, and users want stability.

---

<div class="post-metadata">

**Author:** ![dhrogoff](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@dhrogoff](https://verificationacademy.com/forums/u/dhrogoff)\
**Post date:** [April 24, 2019, 7:34pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/11 "2019-04-24T19:34:29Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/10):_

> _In reply to [dhrogoff](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/10):_  
> It doesn’t matter where the wildcard export statement is located in the package. Whatever was actually imported by the point of the endpackage gets exported.

Makes sense. Thanks.

> The 1800 SystemVerilog committee has been dormant for the last 3 years. Vendors needed a chance to catch up after too many years of change, and users want stability.

Understandable

---

<div class="post-metadata">

**Author:** ![ramankaur09](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ramankaur09](https://verificationacademy.com/forums/u/ramankaur09)\
**Post date:** [November 10, 2021, 12:26pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/12 "2021-11-10T12:26:53Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/11):_  
Hello Dave,  
Hope you doing good  
I have a dummy uvm environment with all components like for environment(seqr,driver,monitor,scoreboard) and a package file (env\_pkg.sv) ,

for sequences( seq\_pkg.sv) and for tests(test\_pkg.sv)

when i try to include these in top file

```verilog
module top;

 import uvm_pkg::*;
`include "uvm_macros.svh" //UVM Library Package
 import seq_pkg::*;
 import env_pkg::*;
logic reset;
logic clk;
axi_intf intf(.clk(clk),.reset(reset));
 
initial
begin
  clk =0;
  reset =0;
  #10ns clk =1;
  reset =1;
end    

always #10 clk = ~clk;

//DUT dut_inst(.clk(intf.clk),.reset(intf.reset));

initial begin
uvm_config_db#(virtual axi_intf)::set(null, "uvm_test_top", "intf", intf);
factory.print();
run_test();

end

```

Iget error as "Error-[SV-LCM-PND] Package not defined  
top.sv, 6  
top, “seq\_pkg::”  
Package scope resolution failed. Token ‘seq\_pkg’ is not a package.  
Originating module ‘top’.  
Move package definition before the use of the package.

Error-[SV-LCM-PND] Package not definedtop.sv, 7  
top, “env\_pkg::”  
Package scope resolution failed. Token ‘env\_pkg’ is not a package.  
Originating module ‘top’.  
Move package definition before the use of the package.  
Please guide ,thnks

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [November 10, 2021, 1:00pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/13 "2021-11-10T13:00:59Z")

</div>

_In reply to [ramankaur09](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/12):_

This error message is stating that the tool can’t find seq\_pkg or env\_pkg. Did you compile them before compiling top.sv?

---

<div class="post-metadata">

**Author:** ![ramankaur09](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ramankaur09](https://verificationacademy.com/forums/u/ramankaur09)\
**Post date:** [November 10, 2021, 3:20pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/14 "2021-11-10T15:20:36Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/13):_  
Hello cgales,  
yes, thats correct reason,thnks for response

---

<div class="post-metadata">

**Author:** ![lumos](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/l/b5e925/32.png) [@lumos](https://verificationacademy.com/forums/u/lumos)\
**Post date:** [April 8, 2022, 1:38pm UTC](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/15 "2022-04-08T13:38:03Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/package-export-does-not-work-like-i-expect/31199/14):_

I tried same think but doesnt work. Do you have any other idea? Thanks for answer
