The GNU Modula-2 front end to GCC

Example compile and link

The gm2 command is the GNU compiler for the Modula-2 language and supports many of the same options as gcc. See (Option Summary, Using the GNU Compiler Collection (GCC)). This manual only documents the options specific to gm2.

This section describes how to compile and link a simple hello world program. It provides a few examples of using the different options mentioned in See (Compiler options, gm2). Assuming that you have a file called hello.mod in your current directory which contains:

MODULE hello ;

FROM StrIO IMPORT WriteString, WriteLn ;

BEGIN
   WriteString('hello world') ; WriteLn
END hello.

You can compile and link it by: gm2 -g hello.mod. The result will be an a.out file created in your directory.

You can split this command into two steps if you prefer. The compile step can be achieved by: gm2 -g -c hello.mod and the link via: gm2 -g -fonlylink hello.mod.

  • To see all the compile actions taken by gm2 users can also add the -v flag at the command line, for example:

    gm2 -v -g -I. hello.mod

    This displays the subprocesses initiated by gm2 which can be useful when trouble shooting.