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