Chapter 21. IMPORT/EXPORT of Types

ASN1C allows productions to be shared between different modules through the ASN.1 IMPORT/EXPORT mechanism. The compiler parses but ignores the EXPORTS declaration within a module. As far as it is concerned, any type defined within a module is available for import by another module.

When ASN1C sees an IMPORT statement, it first checks its list of loaded modules to see if the module has already been loaded into memory. If not, it will attempt to find and parse another source file containing the module. The logic for locating the source file is as follows:

  1. The configuration file (if specified) is checked for a <sourceFile> element containing the name of the source file for the module. Note that the <oid> configuration item can be used to distinguish modules that have the same names but different object identifiers.

  2. If this element is not present, the compiler looks for a file with the name <ModuleName>.asn where module name is the name of the module specified in the IMPORT statement.

In both cases, the –I command line option can be used to tell the compiler where to look for the files.

The other way of specifying multiple modules is to include them all within a single ASN.1 source file. It is possible to have an ASN.1 source file containing multiple module definitions in which modules IMPORT definitions from other modules. An example of this would be the following:

   ModuleA DEFINITIONS ::= BEGIN
      IMPORTS B From ModuleB;
         
       A ::= B
         
   END
         
   ModuleB DEFINITIONS ::= BEGIN
         
      B ::= INTEGER
         
   END

This entire fragment of code would be present in a single ASN.1 source file.