1 .de Sp \" Vertical space (when we can't use .PP)
5 .TH mcs 1 "6 January 2001"
7 mcs \- Mono C# Compiler
10 [option] [source-files]
12 mcs is the Mono C# compiler, an implementation of the ECMA-334
13 language specification. You can pass one or more options to drive the
14 compiler, and a set of source files. Extra options or arguments can
15 be provided in a response file. Response files are referenced by
16 prepending the @ symbol to the response file name.
20 compiler is used to compile against the latest Mono Base Class Library
21 version and fully implements C# 1.0, 2.0, 3.0, 4.0, 5.0 and 6.0
24 See the section on packages for more information.
26 The Mono C# compiler accepts the same command line options that the
27 Microsoft C# compiler does. Those options can start with a slash or a
28 dash (/checked is the same as -checked). Additionally some GNU-like
29 options are supported, those begin with "--". All MCS-specific flags
30 which are not available in the Microsoft C# compiler are available
31 only with the GNU-style options.
33 C# source files must end with a ".cs" extension. Compilation of C#
34 source code requires all the files that make up a library, module or
35 executable to be provided on the command line. There is no support
36 for partial compilation. To achieve the benefits of partial
37 compilation, you should compile programs into their own assemblies,
38 and later reference them with the "-r" flag.
40 The Mono C# compiler generates images (.exe files) that contain CIL
41 byte code that can be executed by any system that implements a Common
42 Language Infrastructure virtual machine such as the Microsoft .NET
43 runtime engine on Windows or the Mono runtime engine on Unix systems.
44 Executables are not bound to a specific CPU or operating system.
46 The Mono C# compiler by default only references three assemblies:
47 mscorlib.dll, System.dll and System.Xml.dll. If you want to
48 reference extra libraries you must manually specify them using the
49 -pkg: command line option or the -r: command line option.
50 Alternatively if you want to get all of the System libraries, you can
51 use the -pkg:dotnet command line option.
56 Displays information about the Mono C# compiler
58 .I \-\-addmodule:MODULE1[,MODULE2]
59 Includes the specified modules in the resulting assembly. Modules are
60 created by calling the compiler with the -target:module option
62 .I -checked, -checked+
63 Sets the default compilation mode to `checked'. This makes all
64 the math operations checked (the default is unchecked).
67 Sets the default compilation mode to `unchecked'. This makes all
68 the math operations unchecked (this is the default).
70 .I -clscheck-, -clscheck+
71 Disables or enables the Common Language Specification (CLS) checks (it
72 is enabled by default).
74 The Common Language Specification (CLS) defines an interoperable
75 subset of types as well as conventions that compilers (CLS producers)
76 and developers must follow to expose code to other programming
77 languages (CLS consumers).
80 Specifies the code page used to process the input files from the
81 point it is specified on. By default files will be processed in the
82 environment-dependent native code page. The compiler will also automatically
83 detect Unicode files that have an embedded byte mark at the beginning.
85 Other popular encodings are 28591 (Latin1), 1252 (iso-8859-1) and 65001 (UTF-8).
87 MCS supports a couple of shorthands: "utf8" can be used to specify utf-8 instead
88 of using the cryptic 65001 and "reset" restores the automatic handling of
89 code pages. These shorthands are not available on the Microsoft compiler.
91 .I \-define:SYMLIST, -d:SYMLIST
92 Defines the symbol listed by the semi-colon separated list SYMLIST
93 SYMBOL. This can be tested in the source code by the pre-processor,
94 or can be used by methods that have been tagged with the Conditional
98 Generate debugging information. To obtain stack traces with debugging
99 information, you need to invoke the mono runtime with the `--debug'
100 flag. The debugging information is stored in a MDB file located in
101 same output folder as produced assembly.
104 Do not generate debugging information.
107 Only embed the strongname public key into the assembly. The actual
108 signing must be done in a later stage using the SN tool. This is useful
109 to protect the private key during development. Note that delay signing
110 can only be done using a strongname key file (not a key container). The
111 option is equivalent to including [assembly: AssemblyDelaySign (true)]
112 in your source code. Compiler option takes precedence over the
116 Default. Strongname (sign) the assembly using the strong name key file
117 (or container). The option is equivalent to including [assembly:
118 AssemblyDelaySign (false)] in your source code. Compiler option takes
119 precedence over the attributes.
122 Extracts the C#/XML documentation from the source code and stores in in
126 This flag is ignored by Mono's C# compiler and is present only to
127 allow MCS to be used as a CSC replacement for msbuild/xbuild.
130 This is used for debugging the compiler. This makes the error emission
131 generate an exception that can be caught by a debugger.
134 This flag is ignored by Mono's C# compiler and is present only to
135 allow MCS to be used as a CSC replacement for msbuild/xbuild.
138 Any source code error or warning issued by the compiler includes file
139 name only by default. This option causes compiler to issue absolute file
143 Strongname (sign) the output assembly using the key pair present in
144 the specified strong name key file (snk). A full key pair is required
145 by default (or when using delaysign-). A file containing only the
146 public key can be used with delaysign+. The option is equivalent to
147 including [assembly: AssemblyKeyFile ("KEYFILE")] in your source code.
148 Compiler option takes precedence over the attributes.
150 .I \-keycontainer:CONTAINER
151 Strongname (sign) the output assembly using the key pair present in
152 the specified container. Note that delaysign+ is ignored when using
153 key containers. The option is equivalent to including [assembly:
154 AssemblyKeyName ("CONTAINER")] in your source code. Compiler option
155 takes precedence over the attributes.
157 .I \-langversion:TEXT
158 The option specifies the version of the language to use. The feature
159 set is different in each C# version. This switch can be used to force
160 the compiler to allow only a subset of the features.
161 The possible values are:
166 Instruct compiler to use the latest version. Equivalent is to omit the
167 switch (this currently defaults to the C# 6.0 language specification).
170 Restrict compiler to use only first ISO standardized features.
171 The usage of features such as generics, static classes, anonymous
172 methods will lead to error.
175 Restrict compiler to use only the second ISO standardized features.
176 This allows the use of generics, static classes, iterators and
177 anonymous methods for example.
180 Restrict the compiler to use only the features available in C# 3.0
181 (a superset of ISO-1 and ISO-2).
184 Restrict the compiler to use only the features available in C# 4.0
188 Restrict the compiler to use only the features available in C# 5.0
192 Restrict the compiler to use only the features available in C# 6.0
196 Enables unstable features from upcoming versions of the language.
198 Notice that this flag only restricts the language features available to
199 the programmer. A version of produced assemblies can be controlled using
206 Each path specified in the comma-separated list will direct the
207 compiler to look for libraries in that specified path.
210 Directs the compiler to look for libraries in the specified path.
211 Multiple paths can be provided by using the option multiple times.
214 Tells the compiler which CLASS contains the entry point. Useful when
215 you are compiling several classes with a Main method.
217 .I \-nostdlib, -nostdlib+
218 Use this flag if you want to compile the core library. This makes the
219 compiler load its internal types from the assembly being compiled.
221 .I \-noconfig, \-noconfig+
222 Disables the default compiler configuration to be loaded. The
223 compiler by default has references to the system assemblies.
226 Makes the compiler ignore warnings specified in the comma-separated
229 .I -optimize, -optimize+, -optimize-
230 Controls compiler code generation optimizations on the code. Using -optimize or
231 -optimize+ will turn on optimizations, -optimize- will turn it off.
232 The default in mcs is to optimize-. The option can be mixed with -debug
233 but for the best debugging experience it is recommended leave the options off.
235 .I -out:FNAME, -o FNAME
236 Names the output file to be generated.
239 Used for benchmarking. The compiler will only parse its input files.
241 .I \-pathmap:K=V[,Kn=Vn]
242 Sets a mapping for source path names used in generated output.
244 .I \-pkg:package1[,packageN]
245 Reference assemblies for the given packages.
247 The compiler will invoke pkg-config --libs on the set of packages
248 specified on the command line to obtain libraries and directories to
251 This is typically used with third party components, like this:
254 $ mcs -pkg:gtk-sharp demo.cs
260 This will instruct the compiler to reference the System.* libraries
261 available on a typical dotnet framework installation, notice that this
262 does not include all of the Mono libraries, only the System.* ones. This
263 is a convenient shortcut for those porting code.
268 Used to specify the target platform. The possible values are: anycpu,
269 anycpu32bitpreferred, arm, x86, x64 or itanium. The default option is
272 .I -resource:RESOURCE[,ID]
273 Embeds to the given resource file. The optional ID can be used to
274 give a different name to the resource. If not specified, the resource
275 name will be the file name.
277 .I -linkresource:RESOURCE[,ID]
278 Links to the specified RESOURCE. The optional ID can be used to give
279 a name to the linked resource.
281 .I -r:ASSEMBLY1[,ASSEMBLY2], \-reference ASSEMBLY1[,ASSEMBLY2]
282 Reference the named assemblies. Use this to use classes from the named
283 assembly in your program. The assembly will be loaded from either the
284 system directory where all the assemblies live, or from the path
285 explicitly given with the -L option.
287 You can also use a semicolon to separate the assemblies instead of a
290 .I -reference:ALIAS=ASSEMBLY
291 Extern alias reference support for C#.
293 If you have different assemblies that provide the same types, the
294 extern alias support allows you to provide names that your software
295 can use to tell those appart. The types from ASSEMBLY will be
296 exposed as ALIAS, then on the C# source code, you need to do:
301 To bring it into your namespace. For example, to cope with two
302 graphics libraries that define "Graphics.Point", one in
303 "OpenGL.dll" and one in "Postscript.dll", you would invoke the
307 mcs -r:Postscript=Postscript.dll -r:OpenGL=OpenGL.dll
310 And in your source code, you would write:
313 extern alias Postscript;
317 // This is a Graphics.Point from Postscrip.dll
318 Postscript.Point p = new Postscript.Point ();
320 // This is a Graphics.Point from OpenGL.dll
321 OpenGL.Point p = new OpenGL.Point ();
325 .I \-recurse:PATTERN, --recurse PATTERN
326 Does recursive compilation using the specified pattern. In Unix the
327 shell will perform globbing, so you might want to use it like this:
330 $ mcs -recurse:'*.cs'
334 Used to specify the version of Base Class Library assemblies used for
335 compilation. Following predefined values are valid: 2, 4 (default) as
336 well as any custom value. The predefined version number means which
337 .NET version should the produced assembly be compatible with. When
338 custom value is specified mcs will try to find Base Class Libraries
339 in the mono installed location PREFIX/lib/mono/<value>.
342 Starts up the compiler in interactive mode, providing a C# shell for
343 statements and expressions. A shortcut is to use the
348 Generates a stack trace at the time the error is reported, useful for
349 debugging the compiler.
351 .I \-target:KIND, \-t:KIND
352 Used to specify the desired target. The possible values are: exe
353 (plain executable), winexe (Windows.Forms executable), library
354 (component libraries) and module (partial library).
357 Another debugging flag. Used to display the times at various points
358 in the compilation process.
360 .I \-unsafe, -unsafe+
361 Enables compilation of unsafe code.
364 Debugging. Turns on verbose yacc parsing.
367 Shows the compiler version.
369 .I \-warnaserror, \-warnaserror+
370 All compilers warnings will be reported as errors.
372 .I \-warnaserror:W1,[Wn], -warnaserror+:W1,[Wn]
373 Treats one or more compiler warnings as errors.
375 .I \-warnaserror-:W1,[Wn]
376 Sets one or more compiler warnings to be always threated as warnings.
377 Becomes useful when used together with -warnaserror.
380 Sets the warning level. 0 is the lowest warning level, and 4 is the
381 highest. The default is 4.
384 Specifies a Win32 resource file (.res) to be bundled into the
388 Attaches the icon specified in FILE on the output into the resulting
392 Use this to stop option parsing, and allow option-looking parameters
393 to be passed on the command line.
395 .SH PACKAGES AND LIBRARIES
396 When referencing an assembly, if the name of the assembly is a path,
397 the compiler will try to load the assembly specified in the path. If
398 it does not, then the compiler will try loading the assembly from the
399 current directory, the compiler base directory and if the assembly is
400 not found in any of those places in the directories specified as
401 arguments to the -lib: command argument.
403 The compiler uses the library path to locate libraries, and is able to
404 reference libraries from a particular package if that directory is
405 used. To simplify the use of packages, the C# compiler includes the
406 -pkg: command line option that is used to load specific collections of
409 Libraries visible to the compiler are stored relative to the
410 installation prefix under PREFIX/lib/mono/ called the PACKAGEBASE and the
411 defaults for mcs, gmcs and smcs are as follows:
414 References the PACKAGEBASE/1.0 directory
417 References the PACKAGEBASE/2.0 directory
420 References the PACKAGEBASE/2.1 directory
422 Those are the only runtime profiles that exist. Although other
423 directories exist (like 3.0 and 3.5) those are not really runtime
424 profiles, they are merely placeholders for extra libraries that build
425 on the 2.0 foundation.
427 Software providers will distribute software that is installed relative
428 to the PACKAGEBASE directory. This is integrated into the
430 tool that not only installs public assemblies into the Global Assembly
431 Cache (GAC) but also installs them into the PACKAGEBASE/PKG directory
432 (where PKG is the name passed to the -package flag to gacutil).
434 As a developer, if you want to consume the Gtk# libraries, you would
435 invoke the compiler like this:
438 $ mcs -pkg:gtk-sharp-2.0 main.cs
441 The -pkg: option instructs the compiler to fetch the definitions for
442 gtk-sharp-2.0 from pkg-config, this is equivalent to passing to the C#
443 compiler the output of:
446 $ pkg-config --libs gtk-sharp-2.0
449 Usually this merely references the libraries from PACKAGEBASE/PKG.
451 Although there are directory names for 3.0 and 3.5, that does not mean
452 that there are 3.0 and 3.5 compiler editions or profiles. Those are
453 merely new libraries that must be manually referenced either with the
454 proper -pkg: invocation, or by referencing the libraries directly.
461 defines have a special meaning to the compiler.
463 By default calls to methods and properties in the
464 System.Diagnostics.Trace class are not generated unless the TRACE
465 symbol is defined (either through a "#define TRACE") in your source
466 code, or by using the
470 By default calls to methods and properties in the
471 System.Diagnostics.Debug class are not generated unless the DEBUG
472 symbol is defined (either through a "#define DEBUG") in your source
473 code, or by using the
477 Note that the effect of defining TRACE and DEBUG is a global setting,
478 even if they are only defined in a single file.
480 .SH DEBUGGING SUPPORT
481 When using the "-debug" flag, MCS will generate a file with the
482 extension .mdb that contains the debugging information for the
483 generated assembly. This file is consumed by the Mono debugger (mdb).
484 .SH ENVIRONMENT VARIABLES
487 If this variable is set, it contains a string in the form
488 "foreground,background" that specifies which color to use to display
489 errors on some terminals.
491 The background is optional and defaults to your terminal current
492 background. The possible colors for foreground are:
493 .B black, red, brightred, green, brightgreen, yellow, brightyellow,
494 blue, brightblue, magenta, brightmagenta, cyan, brightcyan, grey,
495 white and brightwhite.
497 The possible colors for background are: black, red, green, yellow,
498 blue, magenta, cyan, grey and white.
500 For example, you could set these variable from your shell:
503 MCS_COLORS=errors=brightwhite,red
506 You can disable the built-in color scheme by setting this variable to
509 During compilation the MCS compiler defines the __MonoCS__ symbol,
510 this can be used by pre-processor instructions to compile Mono C#
511 compiler specific code. Please note that this symbol is only to test
512 for the compiler, and is not useful to distinguish compilation or
513 deployment platforms.
515 The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap,
516 Martin Baulig, Marek Safar and Raja Harinath. The development was
517 funded by Ximian, Novell and Marek Safar.
520 The Mono Compiler Suite is released under the terms of the GNU GPL or
521 the MIT X11. Please read the accompanying `COPYING' file for details.
522 Alternative licensing for the compiler is available from Xamarin.
525 csharp(1), mono(1), pkg-config(1), sn(1)
528 To report bugs in the compiler, you must file them on our bug tracking
530 http://www.mono-project.com/community/bugs/
532 The Mono Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/
534 The Mono C# compiler was developed by Novell, Inc
535 (http://www.novell.com) and Xamarin Inc (http://www.xamarin.com) is based on the
536 ECMA C# language standard available here:
537 http://www.ecma.ch/ecma1/STAND/ecma-334.htm
539 The home page for the Mono C# compiler is at http://www.mono-project.com/docs/about-mono/languages/csharp/