The GNU Modula-2 front end to GCC

Example compile and link

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 . Assuming that you have a file called hello.mod in your current directory which contains:

MODULE hello ;

FROM StrIO IMPORT WriteString, WriteLn ;

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

You should be able to compile and link it by: gm2 -g hello.mod. The result should 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 compile larger projects consisting of many modules you might find the option -fmakeall useful. For example to compile this tiny example using this option you can use the following command line:

gm2 -g -I. -fmakeall hello.mod

which will read the file hello.mod work out the dependancies and proceed to compile any dependant module whose source is in the directory determined by -I..

  • 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. -fmakeall hello.mod

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