C# compiler Command-line options
Contents
Simple compile
Monos C# compiler is fully compatible the the MS compiler and has
even the same switches.
// Hello World! : hello.cs
using System;
class Hello {
static void Main() {
Console.WriteLine ("Hello, World!");
}
}
To compile, type
mcs hello.cs
This results in a file hello.exe, that you can execute with mono:
mono hello.exe
Out Parameters
To compile to another filename:
mcs /out:someothername.exe hello.cs
Using Targets
Exe
This is the default and will create a console application.
mcs /target:exe hello.cs
Winexe
This has no effect currently, when used with mono, but this might
change, when mono will integrate with GUI filemangers like
Nautilus. On the MS .NET Framework this causes the runtime not to
open a console window, if not already opened.
mcs /target:winexe hello.cs
Library
to compile a library:
mcs /target:library hello.cs
Module
A module is not a complete application, but only for example one or
two classes. Serveral module can be compiled to one application.
This is useful if you want to compile one application out of a
VB.NET module and a C# module.
mcs /target:module hello.cs
Other Options
--about
Displays information about the Mono C# compiler
-checked, -checked
Sets the default compilation mode to `checked'. This makes all the
math operations checked (the default is unchecked).
-checked-
Sets the default compilation mode to `unchecked'. This makes all
the math operations unchecked (this is the default).
-codepage:ID
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. The
special ID "utf8" can be used to switch to utf8 and the ID "reset"
restores the automatic handling of code pages.
-define:SYMLIST, -d:SYMLIST
Defines the symbol listed by the semi-colon sepa- reted 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 Con- ditional attribute.
-debug, -debug+, -g
Generate debugging information. The debugging information is stored
in a file with the extension .dbg (if you install system wide
assemblies, you need to install this file as well). To get stack
traces with debugging information, you need to invoke the mono
runtime with the `--debug' flag.
-debug-
Do not generate debugging information.
--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.
--fatal
This is used for debugging the compiler. This makes the error
emission generate an exception that can be caught by a debugger.
--stacktrace
Generates a stack trace at the time the error is reported, useful
for debugging the compiler.
-lib:PATHLIST
Each path specified in the comma-separated list will direct the
compiler to look for libraries in that specified path.
-L PAT
Directs the compiler to look for libraries in the specified path.
Multiple paths can be provided by using the option multiple times.
-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.
-nowarn:WARNLIST
Makes the compiler ignore warnings specified in the comma-separeted
list WARNLIST>
-out:FNAME, -o FNAME
Names the output file to be generated.
--parse
Used for benchmarking. The compiler will only parse its input
files.
-resource:RESOURCE[,ID]
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.
-linkresource:RESOURCE[,ID]
Links to the specified RESOURCE. The optional ID can be used to
give a name to the linked resource.
-recurse:PATTERN, --recurse PATTERN
Does recursive compilation using the specified pat- tern. In Unix
the shell will perform globbing, so you migth want to use it like
this: bash$ mcs -recurse:'*.cs'
--timestamp
Another debugging flag. Used to display the times at various points
in the compilation process.
-unsafe, -unsafe+
Enables compilation of unsafe code.
-warnaserror, -warnaserror+
Treat warnings as errors.
-warn:LEVEL
Sets the warning level. 0 is the lowest warning level, and 4 is the
highest. The default is 2.
-r:ASSEMBLY1[,ASSEMBLY2], -r ASSEMBLY1[,ASSEMBLY2]
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.
-v
Debugging. Turns on verbose yacc parsing.
--
Use this to stop option parsing, and allow option- looking
parameters to be passed on the command line.
A. Credits
Author: Johannes Roith
(johannes@jroith.de)