ASN1C C/C++ Tutorial
Getting Started with the ASN1C C / C++ Command Line
This tutorial will help users use the ASN1C complier using the terminal shell prompt. Please note that tutorial assumes you are operating in a Linux system.
Change directory to the C BER employee sample directory:
cd c/sample_ber/employee
Run ASN1C to compile the files.
To generate C code for the included employee example, type the following on the command line:../../../bin/asn1c employee.asn -c -ber
To generate C++ code, replace -c with -c++ in the previous command.
Run the C / C++ compiler.
Note: This tutorial shows how to use the GNU gcc/g++ compiler, but the procedure for other compilers would be similar.
At a minimum, the -c and -I options are necessary to compile the employee.c (or employee.cpp) file. -I is used to specify include directories. The command line argument would be:
gcc -c -I../../.. *.c
For C++, replace gcc with g++ and .c with .cpp in the previous command.
The same command would be required to compile the reader.c and writer.c programs.
Link the writer program with the runtime libraries:
gcc -o writer writer.o Employee.o EmployeeEnc.o EmployeeDec.o -L../../lib -lasn1ber -lasn1rt
Link the reader program with the runtime libraries:
gcc -o reader reader.o Employee.o EmployeeEnc.o EmployeeDec.o EmployeePrint.o -L../../lib -lasn1ber -lasn1rt
The writer and reader programs can now be run to encode and decode ASN.1 messages.
Note: A makefile and a Visual Studio project file (Microsoft Windows only) contain all of these commands. These files are included in the sample directory.