Running ASN1C from the Command-line

The ASN1C compiler distribution contains command-line compiler executables as well as a graphical user interface (GUI) wizard that can aid in the specification of compiler options. This section describes how to run the command-line version; the next section describes the GUI.

To test if the compiler was successfully installed, enter asn1c with no parameters as follows (note: if you have not updated your PATH variable, you will need to enter the full pathname):

       asn1c

You should observe the following display (or something similar):

ASN1C Compiler, Version 7.7.x
Copyright (c) 1997-2023 Objective Systems, Inc. All Rights Reserved.

Licensed Copy. Registered To: Objective Systems

Usage: asn1c <filename> <options>

    <filename>          ASN.1 or XSD source filename(s).  Multiple filenames
                          may be specified.  * and ? wildcards are allowed.
                        can also be an ASN1C GUI .acproj file.

  language options:
    -c                  generate C code
    -c++                generate C++ code
    -c++11              generate C++ code that uses C++11 features
    -c#                 generate C# code
    -java               generate Java code
    -cldc               generate Java ME CLDC compatible code
    -python             generate Python code
    -go                 generate Go language code
    -xsd [<filename>]   generate XML schema definitions

  encoding rule options:
    -ber                generate BER encode/decode functions
    -cer                generate CER encode/decode functions
    -der                generate DER encode/decode functions
    -oer                generate OER encode/decode functions
    -coer               generate canonical OER encode/decode functions
    -mder               generate MDER encode/decode functions
    -per                generate PER encode/decode functions
    -aper               generate aligned PER encode/decode functions
    -uper               generate unaligned PER encode/decode functions
    -xer                generate XER encode/decode functions
    -xml                generate XML encode/decode functions
    -json | -jer        generate JSON encode/decode functions
    -jer+               generate JSON encode/decode functions with ObjSys
                          extensions
    -avn                generate ASN.1 Value Notation encode/decode functions
                           (currently C/C++ only)
    -3gl3               generate 3GPP layer 3 encode/decode functions

  basic options:
    -asn1 [<file>]      generate pretty-printed ASN.1 source code
    -asnstd <std>       set standard to be used for parsing ASN.1
                        source file. Possible values - x208, mixed, x680,
                        x680-2021, x680-2015, x680-2008 (default is x680)
    -client             generate sample socket writer client program
    -compact            generate compact code
    -compat <version>   generate code compatible with previous
                        compiler version. <version> format is
                        x.x (for example, 5.3)
    -config <file>      specify configuration file
    -depends            compile main file and dependent IMPORT items
    -events             generate code to invoke SAX-like event handlers
    -raw-events         generate code to invoke raw event handlers, designed
                        to minimize decoding operations, compared to -events
                        (C/C++ and PER only)
    -gen-from-template <file> generate a program from a template
    -genjrtkey          generate Java _Rtkey.java runtime license
    -genlic [<filename>] generate runtime license file
    -genTest [<filename>] generate sample test functions
    -html               generate HTML marked-up version of ASN.1
    -I <directory>      set import file directory
    -lax                do not generate constraint checks in code
    -laxsyntax          do not do a thorough ASN.1 syntax check
    -list               generate listing
    -allow-ambig-tags   allow ambiguous tags in input specifications
    -noaccomment        do not generate the asn1c command line comment
    -noContaining       do not generate inline type for CONTAINING <type>
    -nodatestamp        do not put date/time stamp in generated files
    -nodecode           do not generate decode functions
    -noencode           do not generate encode functions
    -noIndefLen         do not generate indefinite length tests
    -noObjectTypes      do not gen types for items embedded in info objects
    -noOpenExt          do not generate open extension elements
    -noPLMN             disable special treatment of PLMNidentity (e.g., from the RANAP specs)
    -noTBCD, -noBCD     disable special treatment of BCD and TBCD strings
    -notypes            do not generate type definitions
    -noxmlns            do not generate XML namespaces for ASN.1 modules
    -o <directory>      set output file directory (also '-srcdir <dir>')
    -libdir <directory> set output libraries directory
    -bindir <directory> set output binary directory
    -objdir <directory> set output object directory
    -prjdir <directory> set the output project directory; this automatically
                           sets sane defaults for the library directory
                           (lib), binary directory (bin), source directory
                           (src), and object directory (obj)
    -proj <file>        incorporate the contents of an ASN1C GUI project file
    -param <name>=<value> create types from param types using given value
    -pdu <type>         designate <type> to be a Protocol Data Unit (PDU)
                        (<type> may be "all" to select all type definitions)
    -usepdu <type>      specify a Protocol Data Unit (PDU) type for which
                        sample reader/writer programs and test code has to
                        be generated
    -print [<filename>] generate print functions
    -prtfmt details | bracetext  format of output generated by print
    -randtest [<filename>] generate run-time random test functions
    -shortnames         reduce the length of compiler generated names
    -strict             strict standards conformance and constraint checking
    -syntaxcheck        do syntax check only (no code generation)
    -reader             generate sample reader program
    -server             generate sample socket reader server program
    -trace              add trace diag msgs to generated code
    -[no]UniqueNames    resolve name clashes by generating unique names
                          For C/C++, default=on; use -noUniqueNames to disable
    -warnings           output compiler warning messages
    -writer             generate sample writer program

  C/C++ code generation options:
    -array              use arrays for SEQUENCE OF/SET OF types
    -arraySize <size>   specify the size of the array variable
    -compare [<filename>] generate comparison functions
    -copy [<filename>]  generate copy functions
    -cppNs <namespace>  add a C++ namespace to generated code (C++ only)
    -default-int-type <value>   specify the default integer type for
                          unconstrained integers: {int8, uint8, int16,
                          uint16, int32, uint32, int64, uint64, string}
    -dynamic            use dynamic memory for strings and arrays
    -dynamicArray       use dynamic arrays for SEQUENCE OF/SET OF types
    -linkedList         use linked-lists for SEQUENCE OF/SET OF types
    -hfile <filename>   C or C++ header (.h) filename
                          (default is <ASN.1 Module Name>.h)
    -cfile <filename>   C or C++ source (.c or .cpp) filename
                          (default is <ASN.1 Module Name>.c)
    -genBitMacros       generate named bit set, clear, test macros
    -genFree            generate memory free functions for all types
    -nofree             for C++ do not generate destructors
    -hdrGuardPfx <pfx>  add prefix to header guard #defines in .h files
    -maxcfiles          generate separate file for each function
    -maxlines <num>     set limit of number of lines per source file
                        (default value is 50000)
    -noBitStr32         do not use BitStr32 type for small bit strings
    -noEnumConvert      do not generate conversion functions for enumerated
                           items (BER/CER/DER/PER only)
    -noInit             do not generate initialization functions
    -oh <directory>     set output directory for header files
    -perIndef           add support for PER indefinite (fragmented) lengths
    -perPadBitStrings   pad bit strings that contain other types to octet
                           boundary
    -prtToStrm [<filename>] generate print-to-stream functions
    -hexStrFmt <hexAsciiDump | formattedHexDump | hexstring>
                        change the output format for hexadecimal strings
                        from the default (hexAsciiDump) to remove ASCII
                        output (formattedHexDump) or to use a single line
                        (hexstring)
    -static             generate static elements (not pointers)
    -stream             generate stream-based encode/decode functions
    -strict-size        strictly interpret size constraints
    -table-unions       generate union structures for table constraints
    -use-enum-types     use generated enum types in code instead of integers
    -x64                generate code for 64-bit architectures

  C/C++ makefile/project options:
    -genMake [<filename>] generate makefile to compile generated code
    -genMakeDLL [<filename>] generate makefile to build DLL
    -genMakeLib [<filename>] generate makefile to build static library
    -make [<filename>]  same as -genMake as described above.
    -maketype spaceopt|timeopt|debug  Type of makefile to generate.
    -vcproj [<version>] generate Visual Studio project files.
                          <version> is 2022, 2019 (default), 2017, 2015, 2013,
                          2012, 2010, 2008, 2005, 2003, vc6 (Windows only).
    -builddll           generate makefile/project to build DLL
    -dll, -usedll       generate makefile/project to use DLL's
    -mt                 generate makefile/project to use multithreaded libs
    -w32                generate VS nmake file for Windows 32-bit O/S
    -w64                generate VS nmake file for Windows 64-bit O/S

  Java options:
    -compare           generate equals and hashcode methods
    -copy              generate clone methods
    -dirs              output Java code to module name dirs
    -genbuild          generate build script
    -genant            generate ant build.xml script
    -genmaven          generate Maven pom.xml
    -gengradle         generate Gradle build.gradle
    -genjsources       generate <modulename>.mk for list of java files
    -getset            generate get/set methods and protected member vars
    -noevents          disable generation of event handler code.  Also
                          disables element tracking for error handling.
    -pkgname <text>    Java package name
    -pkgpfx <text>     Java package prefix
    -tables            generate table constraint functions
    -genmetadata       generate methods for accessing ASN.1 meta data
                          like value range constraints and optional elements
    -xmlpull           generate code using XmlPull XML parser API (default)
    -stax              generate code using StAX XML parser API

  C# options:
    -compare           generate Equals and Hashcode methods
    -nspfx <text>      C# namespace prefix
    -namespace <text>  C# namespace name
    -dirs              output C# code to module name dirs
    -csfile <filename> generate one .cs file or one per module (*.cs)
    -cskeyfile <name>  have generated makefiles or Visual Studio project
                       files sign the assembly with the indicated strongly
                       named key (.snk) file
    -dotnetv5          generate .Net v5 .csproj files (if used with -vcproj)
    -dotnetv6          generate .Net v6 .csproj files (if used with -vcproj)
    -gencssources      generate <modulename>.mk for list of C# files
    -genMake           generate makefile to build generated code
    -tables            generate table constraint functions
    -vcproj [version]  generate Visual Studio C# project files.
                          [version] is 2022, 2019 (default), 2017, 2015, 2013,
                          2012, 2010, 2008, 2005.
                          (Windows only)
    -genmetadata       generate methods for accessing ASN.1 metadata such
                          as value range constraints and optional elements
  Python options:
    -genbuild [<filename>] create build script to generate code

  Go options:
    -go-rt-inc <modules>  force inclusion of Go run-time module files
    -no-go-main        do not generate main.go file
    -pkgname <text>    Go package name

  XSD options:
    -appinfo [<items>] generate appInfo for ASN.1 items
                         <items> can be tags, enum, and/or ext
                         ex: -appinfo tags,enum,ext
                         default = all if <items> not given
    -attrs [<items>]   generate non-native attributes for <items>
                         <items> is same as for -appinfo
    -targetns [<namespace>] Specify target namespace
                         <namespace> is namespace URI, if not given
                         no target namespace declaration is added
    -useAsn1Xsd        reference types in asn1.xsd schema

  license options:
    -lickey <key>      set license key value
            @<file>    read license key value from file
    -licdeact          deactivate existing license
    -licinstall <file> install license file

To use the compiler, at a minimum, an ASN.1 or XSD source file must be provided. The source file specification can be a full pathname or only what is necessary to qualify the file. If directory information is not provided, the user's current default directory is assumed. If a file extension is not provided, the default extension ".asn" is appended to the name. Multiple source filenames may be specified on the command line to compile a set of files. The wildcard characters ‘*’ and ‘%’ are also allowed in source filenames (for example, the command asn1c *.asncode> will compile all ASN.1 files in the current working directory). It is also possible to provide a list of source files by adding all file specifications to a text file, one per line, and then providing the path to the text file prefixed with an '@' character.

The source file(s) must contain ASN.1 productions that define ASN.1 types and/or value specifications. This file must strictly adhere to the syntax specified in ASN.1 standard ITU-T X.680. The -asnstd x208 command-line option should be used to parse files based on the 1990 ASN.1 standard (x.208) or that contain references to ROSE macro specifications.

Specifying an ASN1C GUI project file with an extension of .acproj is also supported. In this case the information in the .acproj file will be incorporated into the asn1c command invocation. Specifying a project file in this way is equivalent to using the -proj qualifier described below.

The following table lists all of the command line options and what they are used for. The options are shown in alphabetical order. Note that the Java, C#, Python, and Go options are not shown here. They are shown in their respective documents.

Option Argument Description
-3gl3 None This option is used to generate code for encoding and decoding 3GPP Layer 3 messages. Support is primarily provided for Non-Access Stratum (NAS) message types as defined in 3GPP TS 24.007, 24.008, 24.301 (LTE-NAS), and 24.501 (NAS Protocol for 5GS). This is meant for use with the C NAS Add-on.
-allow-ambig-tags None This option suppresses the check that is done for ambiguous tags within a SEQUENCE or SET type within a specification. Special code is generated for the decoder that assigns values to ambiguous elements within a SET in much the same way as would be done if the elements were declared to be in a SEQUENCE. This option used to be called -noAmbigTag.
-aper None This option is used to specify the generation of code to support the aligned variant of the Packed Encoding Rules (PER). This provides for more efficient code than the -per option because checks that were being done at run-time are now done at compile time.
-appInfo <items>

This option only has meaning when generating an XML schema definitions (XSD) file using the -xsd option.

It instructs the compiler to generate an XSD application information section (<appinfo>) for certain ASN.1-only items. The items are specified as a comma-delimited list. Valid values for items are tags, enum, and ext.

<items> is an optional parameter. If it is not specified, it is assumed that application information should be produced for all three item classes: ASN.1 tags, ASN.1 enumerations, and extended elements.

-array none

This option specifies that an array type will be used for SEQUENCE OF/SET OF constructs.

-arraySize <size>

This option specifies the default size of static array variables. This will be overridden by the value of a SIZE constraint on the given type, if it exists.

-asn1 <filename> This option causes pretty-printed ASN.1 to be generated to the given file name or to stdout if no filename was given. Besides the obvious use of providing neatly formatted ASN.1 source code, the option is also useful for producing ASN.1 source code from XML schema document (XSD) files as well as producing trimmed specifications when <include> or <exclude> configuration directives are used.
-asnstd

x680
x680-2021
x680-2015
x680-2008
mixed
x208

This option selects the version of ASN.1 syntax to be parsed. ‘x680’ (the default) refers to modern ASN.1 as specified in the ITU-T X.680-X.690 series of standards. Refer to the section called “ASN.1 Standard Revisions” for more information.
-attrs <items>

This option only has meaning when generating an XML schema definitions (XSD) file using the -xsd option.

It instructs the compiler to generate non-native attributes for certain ASN.1-only items that cannot be expressed in XSD. The items are specified as a comma-delimited list. Valid values for items are tags, enum, and ext.

<items> is an optional parameter. If it is not specified, it is assumed that application information should be produced for all three item classes: ASN.1 tags, ASN.1 enumerations, and extended elements.

-avn None This option is used to generate encode/decode functions for the parsing and formatting of data in ASN.1 Value Notation (AVN) format as document in the X.680 ASN.1 standard.
-ber None This option is used to generate encode/decode functions that implement the Basic Encoding Rules (BER) as specified in the X.690 ASN.1 standard.
-bindir <directory> This option is used in conjunction with the -genMake option to specify the name of the binary executable directory to be added to the makefile. Linked executable programs will be output to this directory.
-bitMacros None This option is used to generate additional macros to set, clear, and test named bits in BIT STRING constructs. By default, only bit number constants are generated. Bit macros provide slightly better performance because mask values required to do the operations are computed at compile time rather than runtime.
-c None Generate C source code.
-c# or -csharp None Generate C# source code. See the ASN1C C# User’s Guide for more information and options for generating C# code.
-c++ or -cpp None Generate C++ source code.
-c++11 or -cpp11 None Generate code that uses C++11 features. This includes the use of std::string for character strings, std::list for lists, and std::array for static arrays. For more information, refer to the sections on type mappings for SEQUENCE OF and for character strings. See also the section on Considerations When Using C++ Standard Library features.
-cer None This option is used to generate encode/decode functions that implement the Canonical Encoding Rules (CER) as specified in the X.690 ASN.1 standard.
-cfile [<filename>] This option allows the specification of a C or C++ source (.c or .cpp) file to which all of the generated encode/decode functions will be written. If not specified, the default is to write to a series of .c or .cpp files based on the ASN.1 module name(s) of the documents being compiled.
-client [<filename>]

This option causes a simple client sample program to be generated that will connect to a server, encode and send a message, and then wait for a response. Once the response is received, it will be printed and the program will terminate.

The template code that is used for the server is located in the server.cpp in the templates directory and may be modified to produce different behavior.

Note that as of this release, only C++ client programs are supported.

-coer [<standard>] This option is used to generate encode/decode functions that implement the Octet Encoding Rules (OER) such that encodings are canonical and decodings are expected to be canonical. If no argument is specified, the x696 standard (ITU-T X.696 / ISO/IEC 8825-7:2014) will be used. If "ntcip" is specified as an argument, then the NTCPIP standard will be used. The -oer option generates OER functions without the canonical enforcement.
-compact None This option is used to generate more compact code at the expense of some constraint and error checking. This is an optimization option that should be used after an application is thoroughly tested.
-compat <versionNumber>

Generate code compatible with an older version of ASN1C. The compiler will attempt to generate code more closely aligned with the given previous release of the compiler.

<versionNumber> is specified as x.x (for example, -compat 5.2)

-config <filename> This option is used to specify the name of a file containing configuration information for the source file being parsed. A full discussion of the contents of a configuration file is provided in the Compiler Configuration File section.
-cppns <namespace> This option is used to add a C++ namespace name to generated C++ files.
-default-int-type <value> This option is used to specify the default integer type for unconstrained integers. Values may be: int8, uint8, int16, uint16, int32, uint32, int64, uint64, and string.
-depends None This option is used to generate a full set of header and source files that contain only the productions in the main file being compiled and items those productions depend on from IMPORT files.
-der None This option is used to generate encode/decode functions that implement the Distinguished Encoding Rules (DER) as specified in the X.690 ASN.1 standard.
-dll None When used in conjunction with the -genMake command-line option, the generated makefile uses dynamically-linked libraries (DLLs in Windows, or .so files in UNIX) instead of statically-linked libraries.
-dynamicArray none

This option specifies that a dynamic array type is to be used for SEQUENCE OF/SET OF constructs.

-fqenum none

The -fqenum (fully-qualified enum) option may be used to make C names unique. When specified, enumerated identifiers will be automatically prefixed with the enclosing type name. This can be useful in situations where common identifiers are often repeated in different types. This is not a problem in C++ because the identifiers are wrapped in a struct declaration which provides a namespace for the values.

-gen-from-template <filename> This option is used to generate an application program from a template file. A template file is a program file with placeholders for items generated by the compiler such as include files and type names.
-genbuild None This option is used to generate a build script when producing Java source code. The generated build script is either a batch file (Windows) or a shell script (UNIX).

-genCompare
-compare

[<filename>]

This option allows the specification of a C or C++ source (.c or .cpp) file to which generated compare functions will be written. Compare functions allow two variables of a given ASN.1 type to be compared for equality.

The <filename> argument to this option is optional. If not specified, the functions will be written to <modulename>Compare.c where <modulename> is the name of the module from the ASN.1 source file.

-genCopy
-copy

[<filename>]

This option allows the specification of a C or C++ source (.c or .cpp) file to which generated copy functions will be written. Copy functions allow a copy to be made of an ASN1C generated variable. For C++, they cause copy constructors and assignment operators to be added to generated classes.

The <filename> argument to this option is optional. If not specified, the functions will be written to <modulename>Copy.c where <modulename> is the name of the module from the ASN.1 source file.

-genFree None This option instructs the compiler to generate a memory free function for each ASN.1 production. Normally, memory is freed within ASN1C by using the rtxMemFree run-time function to free all memory at once that is held by a context. Generated free functions allow finer grained control over memory freeing by just allowing the memory held for specific objects to be freed.
-genMake [<filename>]

This option instructs the compiler to generate a portable makefile for compiling generated C or C++ code. If used with the -w32 command-line option, a makefile that is compatible with the Microsoft Visual Studio nmake utility is generated; otherwise, a GNU-compatible makefile is generated.

Note that the -nmake option may be used instead of the -make -w32 combination to produce a Visual Studio makefile.

-genMakeDLL [<filename>] This option instructs the compiler to generate a portable makefile for compiling the generated C or C++ code into a Dynamic Link Library (DLL).
-genMakeLib [<filename>] This option instructs the compiler to generate a portable makefile for compiling the generated C or C++ code into a static library file.

-genPrint 
-print

[<filename>]

This option allows the specification of a C or C++ source (.c or .cpp) file to which generated print functions will be written. Print functions are debug functions that allow the contents of generated type variables to be written to stdout.

The <filename> argument to this option is optional. If not specified, the print functions will be written to <modulename>Print.c where <modulename> is the name of the module from the ASN.1 source file.

-genPrtToStr 
-prtToStr

[<filename>]

This option allows the specification of a C or C++ source (.c or .cpp) file to which generated "print-to-string" functions will be written. "Print-to-string" functions are similar to print functions except that the output is written to a user-provided text buffer instead of stdout. This makes it possible for the use to display the results on different output devices (for example, in a text window).

The <filename> argument to this option is optional. If not specified, the functions will be written to <modulename>Print.c where <modulename> is the name of the module from the ASN.1 source file.

-genPrtToStrm 
-prtToStrm

[<filename>]

This option allows the specification of a C or C++ source (.c or .cpp) file to which generated "print-to-stream" functions will be written. "Print-to-stream" functions are similar to print functions except that the output is written to a user-provided stream instead of stdout. The stream is in the form of an output callback function that can be set within the run-time context making it possible to redirect output to any type of device.

The <filename> argument to this option is optional. If not specified, the functions will be written to <modulename>Print.c where <modulename> is the name of the module from the ASN.1 source file.

-genTables
-tables

[<filename>] This option is used to generate additional code for the handling of table constraints as defined in the X.682 standard. See the Generated Information Object Table Structures section for additional details on the type of code generated to support table constraints. Note: An alternaitve option for C/C++ is -table-unions which generates union structures for table constraints. These are generally easier to work with then the legacy void pointer approach used in this option.
-genTest [<filename>]

This option allows the specification of a C or C++ source (.c or .cpp) file to which generated "test" functions will be written. "Test" functions are used to populate an instance of a generated PDU type variable with random test data. This instance can then be used in an encode function call to test the encoder. Another advantage of these functions is that they can act as templates for writing your own population functions.

The <filename> argument to this option is optional. If not specified, the functions will be written to <modulename>Test.c where <modulename> is the name of the module from the ASN.1 source file.

-go None Generate Go source code. See the ASN1C Go User’s Guide for more information and options for generating Go code.
-hdrGuardPrefix [<prefix>] This option allows the specification of a prefix that will be used in the generated #defines that are added to header files to make sure they are only included once.
-hexStrFmt

hexAsciiDump
formattedHexDump
hexstring

Setting the hex string format allows users to change how OCTET STRINGs and uninterpreted open types are printed. The default behavior is to output a formatted dump with hex and printable ASCII characters side-by-side: this is the hexAsciiDump option. formattedHexDump removes the ASCII component, and hexstring removes additional formatting, so that the hex content is printed in a single string prefixed by 0x.
-hfile [<filename>] This option allows the specification of a header (.h) file to which all of the generated typedefs and function prototypes will be written. If not specified, the default is <modulename>.h where <modulename> is the name of the module from the ASN.1 source file. If the specified file doesn't end in .h, the .h extension will be added.
-html None This option is used to generated HTML markup for every compiled ASN.1 file. This markup contains hyperlinks to all referenced items within the specifications. One HTML file is generated for each corresponding ASN.1 source file.
-I <directory> This option is used to specify a directory that the compiler will search for ASN.1 source files for IMPORT items. Multiple –I qualifiers can be used to specify multiple directories to search. It is also possible to provide a list of import directories by adding all directory specifications to a text file, one per line, and then providing the path to the text file prefixed with an '@' character (for example, -I @incdirs.txt).
-java None Generate Java source code. See the ASN1C Java User’s Guide for more information on Java code generation.
-json or -jer None This option is used to generate encode/decode functions that implement the Javascript Object Notation (JSON) Encoding Rules (JER) as specified in the X.697 ASN.1 standard. (Note: -jer+ is no longer supported. Similar functionality is now standard JER.)
-lax None This option instructs the compiler to not generate code to check constraints. When used in conjunction with the -compact option, it produces the smallest code base for a given ASN.1 specification.
-laxsyntax None This option instructs the compiler to not do a thorough syntax check when compiling a specification and to generate code even if the specification contains non-fatal syntax errors. Use of the code generated in this case can have unpredictable results; however, if a user knows that certain parts of a specification are not going to be used, this option can save time.
-libdir <directory> This option is used in conjunction with the -genMake option to specify the name of the library directory to be added to the makefile.
-licdeact None This option is used to deactivate any existing licenses that may be in place. This includes the deletion of all license files and other artifcats.
-licinstall <filename> This option is used to install a given osyslic.txt or RLM license file. It will ensure any old licenses are first deactivated before copying the file to the proper location. This is the recommended way to install a license file rather than copying it to one of the known search paths.
-lickey <key-value> or @<file> This option is used to enter a license key value that was provided to the user to enable the compiler for either evaluation or permanent use. The @<file> option can be used to read the key value from a text file.
-linkedList none

This option specifies that a linked-list type is to be used for SEQUENCE OF/SET OF constructs.

-list None Generate listing. This will dump the source code to the standard output device as it is parsed. This can be useful for finding parse errors.
-maxcfiles None Maximize number of generated C files. This option instructs the compiler to generate a separate .c file for each generated C function. In the case of C++, a separate .cpp file is generated for each control class, type, and C function. This is a space optimization option - it can lead to smaller executable sizes by allowing the linker to only link in the required program module object files.
-maxlines <number>

This option is used to specify the maximum number of lines per generated .c or .cpp file. If this number is exceeded, a new file is started with a "_n" suffix where "n" is a sequential number. The default value if not specified is 50,000 lines which will prevent the VC++ "Maximum line numbers exceeded" warning that is common when compiling large ASN.1 source files.

Note that this number is approximate - the next file will not be started until this number is exceeded and the compilation unit that is currently being generated is complete.

-mder None This option is used to generate functions that implement the Medical Device Encoding Rules (MDER) as specified in the IEEE/ISO 11073 standard.
-mt None When used in conjunction with the -genMake command-line option, the generated makefile uses multi-threaded libraries.
-nmake [<filename>] This option instructs the compiler to generate a Visual Studio compatible makefile. It is equivalent to using the -genMake -w32 combination of command-line options.
-noaccomment None This option suppresses the generation of the comment that shows the asn1c command that was used to generate the code.
-noContaining None This option suppresses the generation of inline code to support the CONTAINING keyword. Instead, a normal OCTET STRING or BIT STRING type is inserted as was done in previous ASN1C versions.
-nodecode None This option suppresses the generation of decode functions.
-noencode None This option suppresses the generation of encode functions.
-nofree None For C++ code generation this option suppresses the generation of destructors, which are normally generated by default.
-noIndefLen None This option instructs the compiler to omit indefinite length tests in generated decode functions. These tests result in the generation of a large amount of code. If it is known that an application only uses definite length encoding, this option can result in a much smaller code base size.
-noInit None

This option is used to suppress the generation of initialization functions. A variable of a generated structure can always be initialized by memset’ing the variable to zero. However, this is not usually the most efficient way to initialize a variable because if it contains large byte arrays, a significant amount of processing is required to set all bytes to zero (and they don’t need to be). Initialization functions provide a smart alternative to memset’ing in that only what needs to be set to zero actually is.

Note that previous versions of ASN1C did not generate initialization functions by default. The -genInit switch has been deprecated in favor of -noInit.

-noEnumConvert None

This option suppresses the generation of utility functions in C and C++ that assist in converting enumerated values to strings and vice versa. XER and XML encodings are unaffected by this option, since conversions are necessary for encoding and decoding.

-noObjectTypes None This option suppresses the generation of application language types corresponding to ASN.1 types embedded within information object definitions.
-noOpenExt None This option suppresses addition of an open extension element (extElem1) in constructs that contain extensibility markers. The purpose of the element is to collect any unknown items in a message. If an application does not care about these unknown items, it can use this option to reduce the size of the generated code.
-noPLMN None If not specified, if the ASN.1 contains a production named PLMNidentity (any case), that production will be treated as an OCTET STRING, regardless of how it may be defined in the ASN.1. But if -noPLMN is specified, this special recognition of PLMNidentity will be disabled, and it will be treated according to its definition in the ASN.1 (frequently TBCD-STRING, although in most cases that is incorrect).
-notypes None This options suppresses the generation of type definitions. It is used in conjunction with the -events options to generate pure parser functions.
-noxmlns None This option suppresses the insertion of XML namespace entries in generated XML documents. This includes xmlns attributes and prefixed names.
-nouniquenames None

This option suppresses the automatic generation of unique names to resolve name clashes in the generated code. Name clashes can occur, for example, if two modules are being compiled that contain a production with the same name. A unique name is generated by prepending the module name to one of the productions to form a name of the form <module>_<name>.

Note that name collisions can also be manually resolved by using the typePrefix, enumPrefix, and valuePrefix configuration items (see the Compiler Configuration File section for more details).

Previous versions of ASN1C did not generate unique names by default. The compiler option -uniquenames has been deprecated in favor of -nouniquenames.

-o <directory> This option is used to specify the name of a directory to which all of the generated files will be written.
-objdir <directory> This option is used in conjunction with the -genMake option to specify the name of the object file directory to be added to the makefile. Compiled object files will be output to this directory.
-oer <standard> This option is used to generate encode/decode functions that implement the Octet Encoding Rules (OER). If no argument is specified, the x696 standard will be used. If "ntcip" is specified as an argument, then the NTCIP standard will be used. Also see the description of the -coer option.
-oh <directory> This option is used to specify the name of a directory to which only the generated header files (*.h) will be written.
-param <name>=<value> This option is used to instantiate all parameterized types within the ASN.1 modules that are being compiled with the given parameter value. In this declaration, <name> refers to the dummy reference in a parameterized type definition and <value> refers to an actual value.
-pdu <typeName>

Designate given type name to be a "Protocol Definition Unit" (PDU) type. This will cause a C++ control class to be generated for the given type. By default, PDU types are determined to be types that are not referenced by any other types within a module. This option allows that behavior to be overridden.

The "all" keyword may be specified for <typeName> to indicate that all productions within an ASN.1 module should be treated as PDU types.

-per None This option is used to generate encode/decode functions that implement the Packed Encoding Rules (PER) as specified in the ASN.1 standards.
-perindef None This option is used to generate encode/decode functions that implement the Packed Encoding Rules (PER) as specified in the ASN.1 standards including support for indefinite (fragmented) lengths.
-prjdir <directory> This option is used to create an automatic project directory structure. If no other directories are specified on the command line, sane defaults are chosen for generated libraries (lib), binaries (bin), sources (src), and objects (obj). This may be useful for those who want a well-defined logical structure to their output without code generation and build artifacts in the top-level directory.
-proj <project file> This option is used to specify an ASN1C GUI project file. If a file is specified, the contents of the project file will be incorporated into the asn1c command invocation. This option is equivalent to specifying a .acproj file as a file argument on the command line.
-prtfmt

bracetext 
details

Sets the print format for generated print functions. The details option causes a line-by-line display of all generated fields in a generated structure to be printed. The bracetext option causes a more concise printout showing only the relevant fields in a C-like brace format. As of release version 6.0, bractext is the default (details was the default or only option in previous versions).
-python None Generate Python source code. See the ASN1C Python User’s Guide for more information on Python code generation.
-randtest None Generate random data test functions that populate variables with random data and run-time rather than compile time. This makes it possible to continually test in a loop with different value combinations being used on every iteration.
-raw-events None This option causes the compiler to generate raw event parser functions. This is only supported for C/C++ and PER. Raw events use numeric identifiers to identify the triggering component and don't automatically decode values to pass to the event handlers, unlike normal event handlers.
-reader None This option causes a simple reader sample program to be generated that will read encoded data from a file and then decode and print the contents.
-server [<filename>]

This option causes a simple server sample program to be generated. This program will listen for a connection on a given port. When a connection request is received, the connection will be established and the program will read a complete message from the client. It will then send a response to the client and terminate.

The template code that is used for the server is located in the server.cpp in the templates directory and may be modified to produce different behavior.

Note that as of this release, only C++ server programs are supported.

-shortnames None Generate a shorter form of an element name for a deeply nested production. By default, all intermediate names are used to form names for elements in nested types. This can lead to very long names for deeply nested types. This option causes only the production name and the last element name to be used to form a generated type name.
-spaceopt None Causes space optimization options to be included in the generated makefile.
-static None This has the same effect as specifying the global <storage> static </storage> configuration item. The compiler will insert static elements instead of pointer variables in some generated structures.
-stream None

This option is used to generate stream-based encoders/decoders instead of memory buffer based. This makes it possible to encode directly to or decode directly from a source or sink such as a file or socket. In the case of BER, it will also cause forward encoders to be generated which will use indefinite lengths for all constructed elements in a message.

Note that stream and memory-buffer based encode/decode functions cannot be used/combined in any way. The two are mutually exclusive. If the -stream option is selected, then only stream-based run-time functions can be used with the generated code.

-strict None

This option is used to enable strict checking for conformance to ASN.1 standards and validation of constraints.

-strict-size None

This option causes strict interpretation of size constraints to be enabled. This may result in the generation of more optimized code as unnecessary size variable holders are eliminated. For example, a declaration of OCTET STRING (SIZE(10)) will result in the generation of a 10 byte static array rather than a structure with a count field and array.

-syntaxcheck None

This option is used to do a syntax check of the ASN.1 source files only. No code is generated.

-table-unions None This option is used to generate union structures for table constraints in C/C++ instead of void pointers as is done when the -tables option is used. These are generally easier to use as they present all options in a user-friendly way.
-targetns <namespace>

This option only has meaning when generating an XML schema definitions (XSD) file using the -xsd option.

It allows specification of a target namespace. <namespace> is a namespace URI; if it is not provided, no target namespace declaration is added to the generated XSD file.

-timeopt None Causes time optimization options to be included in the generated makefile.
-trace None This option is used to tell the compiler to add trace diagnostic messages to the generated code. These messages cause print statements to be added to the generated code which print entry and exit information for the generated functions; this can help with isolating encode/decode problems to a given function. This option also enables bit tracing for PER messages. PER bit tracing helps identify how the PER encoder/decoder is treating all of the bits in an encoding. This option is a debugging option that should only be used when debugging, since it adversely affects performance.
-uper None This option is used to specify the generation of code to support the unaligned variant of the Packed Encoding Rules (PER). This provides for slightly more compact code than the -per option because alignment checks are removed from the generated code.
-use-enum-types None This option is used to specify that generated enumerated types are to be used directly in the code as opposed to integer types. The advantages of integer types are a) they are of a known size, and b) they can store unknown identifiers that may be received for extensible enumerated types. However, the direct use of enumerated types makes it easier to inspect variables using the debugger in various IDE's.
-usepdu <PDU type name> This option is used to specify the name of the Protocol Data Unit (PDU) type to be used in generated reader and writer programs.
-vcproj


vc6
2003
2005
2008
2010
2012
2013
2015
2017
2019
2022

This option is used to generate Visual C++- or Visual Studio-compatible project files to compile generated source code. This is a Windows-only option. By passing one of the listed years, the compiler will generate a project that links against libraries provided for those versions of Visual Studio or Visual C++. For example, specifying 2013 will generate a project that links against libraries in the *_vs2013 directory. Not specifying a year will cause the compiler to link against libraries compiled for Visual Studio 2017.

A custom build rule is generated that deletes the generated source files and then invokes ASN1C to regenerate them when a rebuild is done. Doing a clean operation will cause the generated source files to be deleted; a subsequent build will regenerate them.

For Visual C++ 6.0 project files you can see this build rule by locating the first ASN.1 file under the Source Files for the project, right clicking it, choosing Settings... and then choosing the Custom Build tab.

For all other Visual Studio project files the procedure to see the custom rule is very similar to that for Visual C++ 6.0, except that you choose Properties when you right click on the first ASN.1 file, and then click on Custom Build Step or Custom Build Tool on the left.

-w32 None This option is used with makefile and/or Visual Studio project generation to indicate the generated file is to be used on a Windows 32-bit system. In the case of makefile generation, this will cause a makefile to be generated that is compatible with the Visual Studio nmake utility.
-w64 None This option is similar to the -w32 option documented above except that it specifies a Windows 64-bit system.
-warnings None Output information on compiler generated warnings.
-writer None This option causes a simple writer sample program to be generated that will encode a binary message and write it to a file.
-x64 None Generate C/C++ code that is compatible with 64-bit architectures. The main change is the use of the size_t type (abstracted to OSSIZE) for size-related variables. Note that it is safe to use this option on 32-bit systems as well.
-xer None This option is used to generate encode/decode functions that implement the XML Encoding Rules (XER) as specified in the X.693 ASN.1 standard. The -xsd option can be used in conjunction with this option to generate a schema describing the XML format.
-xml None This option is used to generate encode/decode functions that encode/ decode data in an XML format that is more closely aligned with World-Wide Web Consortium (W3C) XML schema. The -xsd option can be used in conjunction with this option to generate a schema describing the XML format.
-xsd [<filename>] This option is used to generate an equivalent XML Schema Definition (XSD) for each of the ASN.1 productions in the ASN.1 source file. If a single ASN.1 module is being compiled, the filename for the XSD file may be specified. Otherwise, the definitions are written to to <modulename>.xsd. There are two supported mappings from ASN.1 to XSD, one corresponding to the -xml option and one corresponding to the -xer option. The default is to follow the -xml variant. If the -xer option is given, then that variant is followed.