Example usage (The GNU Modula-2 Compiler)

### 2.1 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 in 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. 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 -fscaffold-main hello.mod`’ and the link via: ‘`gm2 -g hello.o`’.

2

#### Footnotes

##### (2)

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 sub processes initiated by ‘`gm2`’ which can be useful when trouble shooting.