Section: User Commands (1)
Updated: 6 January 2001
Index Return to Main Contents


mcs, gmcs - Mono C# Compiler (1.0 and 2.0)  


mcs [option] [source-files]  


mcs is the Mono C# compiler, an implementation of the ECMA-334 language specification. You can pass one or more options to drive the compiler, and a set of source files. Extra options or arguments can be provided in a response file. Response files are referenced by prepending the @ symbol to the response file name.

The mcs compiler is used to compile against the 1.x profile and implements C# 1.0 and 2.0 with the exception of generics and nullable types. The gmcs compiler is used to compile against the 2.x profile and implements the complete C# 2.0 specification including generics.

The Mono C# compiler accepts the same command line options that the Microsoft C# compiler does. Those options can start with a slash or a dash (/checked is the same as -checked). Additionally some GNU-like options are supported, those begin with "--". All MCS-specific flags which are not available in the Microsoft C# compiler are available only with the GNU-style options.

C# source files must end with a ".cs" extension. Compilation of C# source code requires all the files that make up a library, module or executable to be provided on the command line. There is no support for partial compilation. To achieve the benefits of partial compilation, you should compile programs into their own assemblies, and later reference them with the "-r" flag.

The Mono C# compiler generates images (.exe files) that contain CIL byte code that can be executed by any system that implements a Common Language Infrastructure virtual machine such as the Microsoft .NET runtime engine on Windows or the Mono runtime engine on Unix systems. Executables are not bound to a specific CPU or operating system.

The Mono C# compiler by default only references three assemblies: mscorlib.dll, System.dll and System.Xml.dll. If you want to reference extra libraries you must manually specify them using the -pkg: command line option or the -r: command line option. Alternatively if you want to get all of the System libraries, you can use the -pkg:dotnet command line option.



Displays information about the Mono C# compiler
Includes the specified modules in the resulting assembly.
-checked, -checked+
Sets the default compilation mode to `checked'. This makes all the math operations checked (the default is unchecked).
Sets the default compilation mode to `unchecked'. This makes all the math operations unchecked (this is the default).
Specifies the code page used to process the input files from the point it is specified on. By default files will be processed in the Latin-1 code page. The compiler will also automatically detect Unicode files that have an embedded byte mark at the beginning.
Other popular encodings are 28591 (Latin1), 1252 (iso-8859-1) and 65001 (UTF-8).
MCS supports a couple of shorthands: "utf8" can be used to specify utf-8 instead
of using the cryptic 65001 and "reset" restores the automatic handling of code pages. These shorthands are not available on the Microsoft compiler.
Defines the symbol listed by the semi-colon separated list SYMLIST SYMBOL. This can be tested in the source code by the pre-processor, or can be used by methods that have been tagged with the Conditional attribute.
-debug, -debug+, -g
Generate debugging information. To obtain stack traces with debugging information, you need to invoke the mono runtime with the `--debug' flag. This debugging information is stored inside the assembly as a resource.
Do not generate debugging information.
Only embed the strongname public key into the assembly. The actual signing must be done in a later stage using the SN tool. This is useful to protect the private key during development. Note that delay signing can only be done using a strongname key file (not a key container). The option is equivalent to including [assembly: AssemblyDelaySign (true)] in your source code. Compiler option takes precedence over the attributes.
Default. Strongname (sign) the assembly using the strong name key file (or container). The option is equivalent to including [assembly: AssemblyDelaySign (false)] in your source code. Compiler option takes precedence over the attributes.
Extracts the C#/XML documentation from the source code and stores in in the given FILE.
--expect-error X L
The compiler will expect the code to generate an error named `X' in line `L'. This is only used by the test suite.
This is used for debugging the compiler. This makes the error emission generate an exception that can be caught by a debugger.
Strongname (sign) the output assembly using the key pair present in the specified strong name key file (snk). A full key pair is required by default (or when using delaysign-). A file containing only the public key can be used with delaysign+. The option is equivalent to including [assembly: AssemblyKeyFile ("KEYFILE")] in your source code. Compiler option takes precedence over the attributes.
Strongname (sign) the output assembly using the key pair present in the specified container. Note that delaysign+ is ignored when using key containers. The option is equivalent to including [assembly: AssemblyKeyName ("CONTAINER")] in your source code. Compiler option takes precedence over the attributes.
The option specifies the version of the language to use. The feature set is different in each C# version. This switch can be used to force the compiler to allow only a subset of the features. The possible values are:

Default - Instruct compiler to use the latest version. Equivalent
is to omit the switch.

ISO-1   - Restrict compiler to use only ISO standardized features.
The usage of features such as generics, static classes, anonymous
methods will lead to error.
Notice that this flag only controls the language features available to
the programmer, it does not control the kind of assemblies produced.
Programs compiled with mcs will reference the 1.1 APIs, Programs
compiled with gmcs reference the 2.0 APIs.
Each path specified in the comma-separated list will direct the compiler to look for libraries in that specified path.
Directs the compiler to look for libraries in the specified path. Multiple paths can be provided by using the option multiple times.
Tells the compiler which CLASS contains the entry point. Useful when you are compiling several classes with a Main method.
-nostdlib, -nostdlib+
Use this flag if you want to compile the core library. This makes the compiler load its internal types from the assembly being compiled.
-noconfig, -noconfig+
Disables the default compiler configuration to be loaded. The compiler by default has references to the system assemblies.
Makes the compiler ignore warnings specified in the comma-separated list WARNLIST>
-optimize, -optimize+, -optimize-
Controls whether to perform optimizations on the code. -optimize and -optimize+ will turn on optimizations, -optimize- will turn it off. The default in mcs is to optimize+.
-out:FNAME, -o FNAME
Names the output file to be generated.
Used for benchmarking. The compiler will only parse its input files.
The compiler will invoke pkg-config --libs on the set of packages specified on the command line to obtain libraries and directories to compile the code.
This is typically used with third party components, like this: $ mcs -pkg:gtk-sharp demo.cs
This will instruct the compiler to reference the System.* libraries available on a typical dotnet framework installation, notice that this does not include all of the Mono libraries, only the System.* ones. This is a convenient shortcut for those porting code.
Embeds to the given resource file. The optional ID can be used to give a different name to the resource. If not specified, the resource name will be the file name.
Links to the specified RESOURCE. The optional ID can be used to give a name to the linked resource.
Reference the named assemblies. Use this to use classes from the named assembly in your program. The assembly will be loaded from either the system directory where all the assemblies live, or from the path explicitly given with the -L option.

You can also use a semicolon to separate the assemblies instead of a comma.

-recurse:PATTERN, --recurse PATTERN
Does recursive compilation using the specified pattern. In Unix the shell will perform globbing, so you might want to use it like this:

                $ mcs -recurse:'*.cs' 
Generates a stack trace at the time the error is reported, useful for debugging the compiler.
-target:KIND, -t:KIND
Used to specify the desired target. The possible values are: exe (plain executable), winexe (Windows.Forms executable), library (component libraries) and module (partial library).
Another debugging flag. Used to display the times at various points in the compilation process.
-unsafe, -unsafe+
Enables compilation of unsafe code.
Debugging. Turns on verbose yacc parsing.
Turns on C# 2.0 language features.
Shows the compiler version.
-warnaserror, -warnaserror+
Treat warnings as errors.
Sets the warning level. 0 is the lowest warning level, and 4 is the highest. The default is 2.
Specifies a Win32 resource file (.res) to be bundled into the resulting assembly.
Attaches the icon specified in FILE on the output into the resulting assembly.
Use this to stop option parsing, and allow option-looking parameters to be passed on the command line.



The TRACE and DEBUG defines have a special meaning to the compiler.

By default calls to methods and properties in the System.Diagnostics.Trace class are not generated unless the TRACE symbol is defined (either through a "#define TRACE") in your source code, or by using the --define TRACE in the command line.

By default calls to methods and properties in the System.Diagnostics.Debug class are not generated unless the DEBUG symbol is defined (either through a "#define DEBUG") in your source code, or by using the --define DEBUG in the command line.

Note that the effect of defining TRACE and DEBUG is a global setting, even if they are only defined in a single file.



When use the "--debug" or "-g" flag, MCS will create an assembler file FILE-debug.s containing debugging information where FILE is the name of the generated assembly. You need to run this file through the assembler to get a object file FILE-debug.o. See mono's "--dwarf-plus" argument for details on how to use this file.  


During compilation the MCS compiler defines the __MonoCS__ symbol, this can be used by pre-processor instructions to compile Mono C# compiler specific code. Please note that this symbol is only to test for the compiler, and is not useful to distinguish compilation or deployment platforms.  


The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar and Raja Harinath. The development was funded by Ximian, Novell and Marek Safar.



The Mono Compiler Suite is released under the terms of the GNU GPL. Please read the accompanying `COPYING' file for details. Alternative licensing for the compiler is available from Novell.



mono(1), mint(1), sn(1)



To report bugs in the compiler, you must file them on our bug tracking system, at:  


The Mono Mailing lists are listed at  


The Mono C# compiler was developed by Novell, Inc (, http) and is based on the ECMA C# language standard available here:

The home page for the Mono C# compiler is at