Chapter 10. 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.

  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.

To avoid having ASN1C search for additional source files, simply provide the definition of each imported module in one of the source files specified as input to ASN1C. The imported module may be defined in its own source file, or multiple module definitions can be located in a single source file. Here is an example of combining modules into a single source file:

   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.