Use of the -maxcfiles Option

The -maxcfiles option allows generation of more compact code by putting each encode, decode, copy, compare, etc function into a separate file. This allows the linker to link in only the required functions as opposed to all functions in a compiled object module. This option might be useful for applications that have minimal space requirements (for example, embedded systems).

Note

Some sophisticated linkers have the capability to pull individual functions out of an object module directly for final inclusion in the target executable or shared object file. In this case, the -maxcfiles option does not provide any advantage in reducing the size of the application program.

To achieve the best results it is necessary to put all compiled object files into an object library (.a or .lib file) and include this library in the link command. The –genMake option when used in conjunction with –maxcfiles will generate a makefile that will compile each of the generated files and add them to a library with a name based on the name of the ASN.1 module being compiled (<moduleName>.lib for Windows or lib<moduleName>.a for *NIX).

The format of each generated .c file name is as follows:

   asn1<suffix>_<prodname>.c

where <suffix> depends on encoding rules and the function type (encode, decode, free, etc.) and <prodname> is the ASN.1 production name.

For example, consider one type definition within the employee.asn ASN.1 specification:

   Employee DEFINITIONS ::= BEGIN
   
   [...]
   
   Name ::= [APPLICATION 1] IMPLICIT SEQUENCE {
      givenName IA5String,
      initial IA5String,
      familyName IA5String
   }
   
   [...]
   
   END

By default, the following .c files would be generated (note: this assumes no additional code generation options were selected):

   Employee.c
   EmployeeEnc.c
   EmployeeDec.c

If -maxcfiles was selected as in the following command line:

   asn1c employee.asn -c -ber -trace –maxcfiles

Running ASN1C with the -maxcfiles option, the following .c files for this type would be generated for the Name type:

   asn1D_Name.c
   asn1E_Name.c

These contain the functions to decode Name and encode Name respectively. Similar files would be generated for the other productions in the module as well.