Compiling and Linking Generated Code

C/C++ source code generated by the compiler can be compiled using any ANSI standard C or C++ compiler. The only additional option that must be set is the inclusion of the ASN.1 C/C++ header file include directory with the –I option.

When linking a program with compiler-generated code, it is necessary to include the ASN.1 run-time libraries. It is necessary to include at least one of the encoding rules libraries (asn1ber, asn1per, or asn1xer) as well as the common run-time functions library (asn1rt). See the ASN1C C/C++ Run-time Reference Manual for further details on these libraries.

For static linking on Windows systems, the name of the library files are asn1ber_a.lib, asn1per_a.lib, or asn1xer_a.lib for BER/DER/CER, PER, XER, or XML respectively, and asn1rt_a.lib for the common run-time components. On UNIX/Linux, the library names are libasn1ber.a, libasn1per.a, libasn1xer.a, libasn1xml.a and libasn1rt.a. The library files are located in the lib subdirectory. For UNIX, the –L switch should be used to point to the subdirectory path and - lasn1ber, -lasn1per, -lasn1xer, -lasn1xml and/or -lasn1rt used to link with the libraries. For Windows, the -LIBPATH switch should be used to specify the library path.

There are several other variations of the C/C++ run-time library files for Windows. The following table summarizes what options were used to build each of these variations:

Library Files Description
asn1rt_a.lib
asn1ber_a.lib
asn1per_a.lib
asn1xer_a.lib
asn1xml_a.lib
Static single-threaded libraries. These are built without -MT (multithreading) and -MD (dynamic link libraries) options. These are not thread-safe. However, they provide the smallest footprint of the different libraries.
asn1rt.lib
asn1ber.lib
asn1per.lib
asn1xer.lib
asn1xml.lib
DLL libraries. These are used to link against the DLL versions of the run-time libraries (asn1rt.dll, etc.)
asn1rtmt_a.lib
asn1bermt_a.lib
asn1permt_a.lib
asn1xermt_a.lib
asn1xmlmt_a.lib

Static multi-threaded libraries. These libraries were built with the -MT option. They should be used if your application contains threads and you wish to link with the static libraries. (The DLLs are also thread-safe.)

In Visual Studio 2005 and greater, all libraries are multi-threaded by default, so these libraries are not available for those versions.

asn1rtmd_a.lib
asn1bermd_a.lib
asn1permd_a.lib
asn1xermd_a.lib
asn1xmlmd_a.lib
DLL-ready multi-threaded libraries. These libraries were built with the –MD option. They allow linking additional object modules in with the ASN1C run-time modules to produce larger DLLs.

For dynamic linking on UNIX/Linux, a shared object version of each run-time library is included in the lib subdirectory. This file typically has the extension .so (for shared object) or .sl (for shared library). See the documentation for your UNIX compiler to determine how to link using these files.

Compiling and linking code generated to support the XML encoding rules (XER) is more complex then the other rules because XER requires the use of third-party XML parser software. This requires the use of additional include directories when compiling and libraries when linking. The C++ sample programs that are provided use the EXPAT XML parser (http://expat.sourceforge.net/). All of the necessary include files and binary libraries are included with the distribution for using this parser. If a different parser is to be used, consult the vendor’s documentation for compile and link procedures.

See the makefile in any of the sample subdirectories of the distribution for an example of what must be included to build a program using generated source code.