Contents Menu Expand Light mode Dark mode Auto light/dark mode
The GNU Modula-2 Compiler 13.0.1 (experimental 20220101) documentation
Logo
The GNU Modula-2 Compiler 13.0.1 (experimental 20220101) documentation
  • Overview of GNU Modula-2
    • What is GNU Modula-2
    • Why use GNU Modula-2
    • Release map
    • News
    • How to get source code using git
    • GNU Modula-2 Features
    • Documentation
    • Regression tests for gm2 in the repository
    • Limitations
    • Objectives
    • FAQ
      • Why use the C++ exception mechanism in GCC, rather than a bespoke Modula-2 mechanism?
    • Community
    • Other languages for GCC
    • Papers and talks
  • Using GNU Modula-2
    • Example compile and link
    • Compiler options
    • GNU Modula-2 related environment variables
    • Elementary data types
    • Permanently accessible base procedures.
      • Standard procedures and functions common to PIM and ISO
      • ISO specific standard procedures and functions
    • GNU Modula-2 supported dialects
      • Integer division, remainder and modulus
    • Exception implementation
    • How to detect runtime problems at compile time
    • GNU Modula-2 language extensions
      • Optional procedure parameter
    • Type compatibility
      • Expression compatibility
      • Assignment compatibility
      • Parameter compatibility
    • Unbounded by reference
    • Building a shared library
    • How to produce swig interface files
      • Limitations of automatic generated of Swig files
    • How to produce a Python module
    • Interfacing GNU Modula-2 to C
    • Interface to assembly language
    • Data type alignment
    • Packing data types
    • Accessing GNU Modula-2 Built-ins
    • The PIM system module
    • The ISO system module
  • Licence of GNU Modula-2
  • EBNF of GNU Modula-2
  • PIM and ISO library definitions
    • Base libraries
      • gm2-libs/ASCII
      • gm2-libs/Args
      • gm2-libs/Assertion
      • gm2-libs/Break
      • gm2-libs/Builtins
      • gm2-libs/COROUTINES
      • gm2-libs/CmdArgs
      • gm2-libs/Debug
      • gm2-libs/DynamicStrings
      • gm2-libs/Environment
      • gm2-libs/FIO
      • gm2-libs/FormatStrings
      • gm2-libs/FpuIO
      • gm2-libs/GetOpt
      • gm2-libs/IO
      • gm2-libs/Indexing
      • gm2-libs/LMathLib0
      • gm2-libs/LegacyReal
      • gm2-libs/M2Dependent
      • gm2-libs/M2EXCEPTION
      • gm2-libs/M2LINK
      • gm2-libs/M2RTS
      • gm2-libs/MathLib0
      • gm2-libs/MemUtils
      • gm2-libs/NumberIO
      • gm2-libs/OptLib
      • gm2-libs/PushBackInput
      • gm2-libs/RTExceptions
      • gm2-libs/RTint
      • gm2-libs/SArgs
      • gm2-libs/SCmdArgs
      • gm2-libs/SEnvironment
      • gm2-libs/SFIO
      • gm2-libs/SMathLib0
      • gm2-libs/SYSTEM
      • gm2-libs/Scan
      • gm2-libs/Selective
      • gm2-libs/StdIO
      • gm2-libs/Storage
      • gm2-libs/StrCase
      • gm2-libs/StrIO
      • gm2-libs/StrLib
      • gm2-libs/StringConvert
      • gm2-libs/SysExceptions
      • gm2-libs/SysStorage
      • gm2-libs/TimeString
      • gm2-libs/UnixArgs
      • gm2-libs/cbuiltin
      • gm2-libs/cgetopt
      • gm2-libs/cxxabi
      • gm2-libs/dtoa
      • gm2-libs/errno
      • gm2-libs/gdbif
      • gm2-libs/ldtoa
      • gm2-libs/libc
      • gm2-libs/libm
      • gm2-libs/sckt
      • gm2-libs/termios
      • gm2-libs/wrapc
    • PIM coroutine support
      • gm2-libs-coroutines/Debug
      • gm2-libs-coroutines/Executive
      • gm2-libs-coroutines/KeyBoardLEDs
      • gm2-libs-coroutines/SYSTEM
      • gm2-libs-coroutines/TimerHandler
    • M2 ISO Libraries
      • gm2-libs-iso/COROUTINES
      • gm2-libs-iso/ChanConsts
      • gm2-libs-iso/CharClass
      • gm2-libs-iso/ClientSocket
      • gm2-libs-iso/ComplexMath
      • gm2-libs-iso/ConvStringLong
      • gm2-libs-iso/ConvStringReal
      • gm2-libs-iso/ConvTypes
      • gm2-libs-iso/EXCEPTIONS
      • gm2-libs-iso/ErrnoCategory
      • gm2-libs-iso/GeneralUserExceptions
      • gm2-libs-iso/IOChan
      • gm2-libs-iso/IOConsts
      • gm2-libs-iso/IOLink
      • gm2-libs-iso/IOResult
      • gm2-libs-iso/LongComplexMath
      • gm2-libs-iso/LongConv
      • gm2-libs-iso/LongIO
      • gm2-libs-iso/LongMath
      • gm2-libs-iso/LongStr
      • gm2-libs-iso/LongWholeIO
      • gm2-libs-iso/LowLong
      • gm2-libs-iso/LowReal
      • gm2-libs-iso/LowShort
      • gm2-libs-iso/M2EXCEPTION
      • gm2-libs-iso/M2RTS
      • gm2-libs-iso/MemStream
      • gm2-libs-iso/Preemptive
      • gm2-libs-iso/Processes
      • gm2-libs-iso/ProgramArgs
      • gm2-libs-iso/RTco
      • gm2-libs-iso/RTdata
      • gm2-libs-iso/RTentity
      • gm2-libs-iso/RTfio
      • gm2-libs-iso/RTgen
      • gm2-libs-iso/RTgenif
      • gm2-libs-iso/RTio
      • gm2-libs-iso/RandomNumber
      • gm2-libs-iso/RawIO
      • gm2-libs-iso/RealConv
      • gm2-libs-iso/RealIO
      • gm2-libs-iso/RealMath
      • gm2-libs-iso/RealStr
      • gm2-libs-iso/RndFile
      • gm2-libs-iso/SIOResult
      • gm2-libs-iso/SLongIO
      • gm2-libs-iso/SLongWholeIO
      • gm2-libs-iso/SRawIO
      • gm2-libs-iso/SRealIO
      • gm2-libs-iso/SShortIO
      • gm2-libs-iso/SShortWholeIO
      • gm2-libs-iso/STextIO
      • gm2-libs-iso/SWholeIO
      • gm2-libs-iso/SYSTEM
      • gm2-libs-iso/Semaphores
      • gm2-libs-iso/SeqFile
      • gm2-libs-iso/ServerSocket
      • gm2-libs-iso/ShortComplexMath
      • gm2-libs-iso/ShortIO
      • gm2-libs-iso/ShortWholeIO
      • gm2-libs-iso/SimpleCipher
      • gm2-libs-iso/StdChans
      • gm2-libs-iso/Storage
      • gm2-libs-iso/StreamFile
      • gm2-libs-iso/StringChan
      • gm2-libs-iso/Strings
      • gm2-libs-iso/SysClock
      • gm2-libs-iso/TERMINATION
      • gm2-libs-iso/TermFile
      • gm2-libs-iso/TextIO
      • gm2-libs-iso/WholeConv
      • gm2-libs-iso/WholeIO
      • gm2-libs-iso/WholeStr
      • gm2-libs-iso/wrapsock
      • gm2-libs-iso/wraptime
    • PIM and Logitech 3.0 Compatible
      • gm2-libs-pim/BitBlockOps
      • gm2-libs-pim/BitByteOps
      • gm2-libs-pim/BitWordOps
      • gm2-libs-pim/BlockOps
      • gm2-libs-pim/Break
      • gm2-libs-pim/CardinalIO
      • gm2-libs-pim/Conversions
      • gm2-libs-pim/DebugPMD
      • gm2-libs-pim/DebugTrace
      • gm2-libs-pim/Delay
      • gm2-libs-pim/Display
      • gm2-libs-pim/ErrorCode
      • gm2-libs-pim/FileSystem
      • gm2-libs-pim/FloatingUtilities
      • gm2-libs-pim/InOut
      • gm2-libs-pim/Keyboard
      • gm2-libs-pim/LongIO
      • gm2-libs-pim/NumberConversion
      • gm2-libs-pim/Random
      • gm2-libs-pim/RealConversions
      • gm2-libs-pim/RealInOut
      • gm2-libs-pim/Strings
      • gm2-libs-pim/Termbase
      • gm2-libs-pim/Terminal
      • gm2-libs-pim/TimeDate
    • Indices
Back to top
Edit this page

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.

Next
Compiler options
Previous
Using GNU Modula-2
Copyright © 2022 Free Software Foundation, Inc.
Made with Sphinx and @pradyunsg's Furo
Last updated on Nov 07, 2022