Example compile and link#
@c man begin SYNOPSIS gm2 gm2 [@option{-c}|@option{-S}] [@option{-g}] [@option{-pg}]
[@option{-O}@var{level}] [@option{-W}@var{warn}…] [@option{-I}@var{dir}…] [@option{-L}@var{dir}…] [@option{-f}@var{option}…] [@option{-m}@var{machine-option}…] [@option{-o} @var{outfile}] [@@@var{file}] @var{infile}…
Only the most useful options are listed here; see below for the remainder. @c man end @c man begin SEEALSO gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for @file{gm2} and @file{gcc}. @c man end The gm2 command is the GNU compiler for the Modula-2 language and supports many of the same options as gcc. See Option Summary. 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
.
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.