Merge pull request #5014 from vkargov/vk-kasha
[mono.git] / man / mcs.1
1 .de Sp \" Vertical space (when we can't use .PP)
2 .if t .sp .5v
3 .if n .sp
4 ..
5 .TH mcs 1 "6 January 2001"
6 .SH NAME 
7 mcs \- Mono C# Compiler
8 .SH SYNOPSIS
9 .B mcs 
10 [option] [source-files]
11 .SH DESCRIPTION
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.
17 .PP
18 The 
19 .I mcs
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
22 specifications.
23 .PP
24 See the section on packages for more information.
25 .PP
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.
32 .PP
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.
39 .PP
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.
45 .PP
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.
52 .PP
53 .SH OPTIONS
54 .TP
55 .I \-\-about
56 Displays information about the Mono C# compiler
57 .TP
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
61 .TP
62 .I -checked, -checked+
63 Sets the default compilation mode to `checked'.  This makes all
64 the math operations checked (the default is unchecked).
65 .TP
66 .I -checked-
67 Sets the default compilation mode to `unchecked'.  This makes all
68 the math operations unchecked (this is the default).
69 .TP
70 .I -clscheck-, -clscheck+
71 Disables or enables the Common Language Specification (CLS) checks (it
72 is enabled by default). 
73 .Sp
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).  
78 .TP
79 .I -codepage:ID
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.   
84 .Sp
85 Other popular encodings are 28591 (Latin1), 1252 (iso-8859-1) and 65001 (UTF-8).
86 .Sp
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.
90 .TP
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
95 attribute. 
96 .TP
97 .I \-debug, \-debug+
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.
102 .TP
103 .I \-debug-
104 Do not generate debugging information.
105 .TP
106 .I \-delaysign+
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 
113 attributes.
114 .TP
115 .I \-delaysign-
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.
120 .TP
121 .I \-doc:FILE
122 Extracts the C#/XML documentation from the source code and stores in in
123 the given FILE.
124 .TP
125 .I \-errorreport
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.
128 .TP
129 .I \-\-fatal 
130 This is used for debugging the compiler.  This makes the error emission
131 generate an exception that can be caught by a debugger.
132 .TP
133 .I \-filealign
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.
136 .TP
137 .I \-fullpaths
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
140 path instead.
141 .TP
142 .I \-keyfile:KEYFILE
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.
149 .TP
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.
156 .TP
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:
162 .RS
163 .ne 8
164 .TP
165 .I "Default"
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).
168 .TP
169 .I "ISO-1"
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.
173 .TP
174 .I "ISO-2"
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.
178 .TP
179 .I "3"
180 Restrict the compiler to use only the features available in C# 3.0
181 (a superset of ISO-1 and ISO-2).
182 .TP
183 .I "4"
184 Restrict the compiler to use only the features available in C# 4.0
185 specification.
186 .TP
187 .I "5"
188 Restrict the compiler to use only the features available in C# 5.0
189 specification.
190 .TP
191 .I "6"
192 Restrict the compiler to use only the features available in C# 6.0
193 specification.
194 .TP
195 .I "experimental"
196 Enables unstable features from upcoming versions of the language.
197 .PP
198 Notice that this flag only restricts the language features available to
199 the programmer. A version of produced assemblies can be controlled using
200 .I SDK
201 option.
202 .ne
203 .RE
204 .TP
205 .I -lib:PATHLIST
206 Each path specified in the comma-separated list will direct the
207 compiler to look for libraries in that specified path.
208 .TP
209 .I \-L 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.
212 .TP
213 .I \-main:CLASS
214 Tells the compiler which CLASS contains the entry point. Useful when
215 you are compiling several classes with a Main method.
216 .TP
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.
220 .TP
221 .I \-noconfig, \-noconfig+
222 Disables the default compiler configuration to be loaded.  The
223 compiler by default has references to the system assemblies. 
224 .TP
225 .I \-nowarn:WARNLIST
226 Makes the compiler ignore warnings specified in the comma-separated
227 list WARNLIST>
228 .TP
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.
234 .TP
235 .I -out:FNAME, -o FNAME
236 Names the output file to be generated.
237 .TP
238 .I \-\-parse
239 Used for benchmarking.  The compiler will only parse its input files.
240 .TP
241 .I \-pathmap:K=V[,Kn=Vn]
242 Sets a mapping for source path names used in generated output.
243 .TP
244 .I \-pkg:package1[,packageN]
245 Reference assemblies for the given packages.
246 .Sp
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
249 compile the code.
250 .Sp
251 This is typically used with third party components, like this:
252 .nf
253
254                 $ mcs -pkg:gtk-sharp demo.cs
255 .fi
256 .RS
257 .ne 8
258 .TP
259 .I \-pkg:dotnet
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.
264 .ne
265 .RE
266 .TP
267 .I \-platform:ARCH
268 Used to specify the target platform. The possible values are: anycpu,
269 anycpu32bitpreferred, arm, x86, x64 or itanium. The default option is
270 anycpu.
271 .TP
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.
276 .TP
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.
280 .TP
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.
286 .Sp
287 You can also use a semicolon to separate the assemblies instead of a
288 comma. 
289 .TP
290 .I -reference:ALIAS=ASSEMBLY
291 Extern alias reference support for C#.
292 .Sp
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:
297 .Sp
298 .nf
299         extern alias ALIAS;
300 .fi
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
304 compiler like this:
305 .Sp
306 .nf
307         mcs -r:Postscript=Postscript.dll -r:OpenGL=OpenGL.dll
308 .fi
309 .Sp
310 And in your source code, you would write:
311 .Sp
312 .nf
313         extern alias Postscript;
314         extern alias OpenGL;
315
316         class X {
317                 // This is a Graphics.Point from Postscrip.dll
318                 Postscript.Point p = new Postscript.Point ();
319
320                 // This is a Graphics.Point from OpenGL.dll
321                 OpenGL.Point p = new OpenGL.Point ();
322         }
323 .fi
324 .TP
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:
328 .PP
329 .nf
330                 $ mcs -recurse:'*.cs' 
331 .fi
332 .TP
333 .I \-sdk:VERSION
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>.
340 .TP
341 .I \-\-shell
342 Starts up the compiler in interactive mode, providing a C# shell for
343 statements and expressions.   A shortcut is to use the
344 .I csharp
345 command directly.
346 .TP
347 .I \-\-stacktrace
348 Generates a stack trace at the time the error is reported, useful for
349 debugging the compiler.
350 .TP
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).
355 .TP
356 .I \-\-timestamp
357 Another debugging flag.  Used to display the times at various points
358 in the compilation process.
359 .TP
360 .I \-unsafe, -unsafe+
361 Enables compilation of unsafe code.
362 .TP
363 .I \-v 
364 Debugging. Turns on verbose yacc parsing.
365 .TP
366 .I \-\-version
367 Shows the compiler version.
368 .TP
369 .I \-warnaserror, \-warnaserror+
370 All compilers warnings will be reported as errors.
371 .TP
372 .I \-warnaserror:W1,[Wn], -warnaserror+:W1,[Wn]
373 Treats one or more compiler warnings as errors.
374 .TP
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.
378 .TP
379 .I \-warn:LEVEL
380 Sets the warning level.  0 is the lowest warning level, and 4 is the
381 highest.  The default is 4.
382 .TP
383 .I \-win32res:FILE
384 Specifies a Win32 resource file (.res) to be bundled into the
385 resulting assembly.
386 .TP
387 .I \-win32icon:FILE
388 Attaches the icon specified in FILE on the output into the resulting
389 assembly.
390 .TP
391 .I \-\-
392 Use this to stop option parsing, and allow option-looking parameters
393 to be passed on the command line.
394 .PP
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.
402 .PP
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
407 libraries. 
408 .PP 
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:
412 .TP 
413 .I mcs
414 References the PACKAGEBASE/1.0 directory
415 .TP
416 .I gmcs
417 References the PACKAGEBASE/2.0 directory
418 .TP
419 .I smcs
420 References the PACKAGEBASE/2.1 directory
421 .PP
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.
426 .PP
427 Software providers will distribute software that is installed relative
428 to the PACKAGEBASE directory.  This is integrated into the 
429 .I gacutil
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).
433 .PP
434 As a developer, if you want to consume the Gtk# libraries, you would
435 invoke the compiler like this:
436 .nf
437
438         $ mcs -pkg:gtk-sharp-2.0 main.cs
439
440 .fi
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:
444 .nf
445
446         $ pkg-config --libs gtk-sharp-2.0
447
448 .fi
449 Usually this merely references the libraries from PACKAGEBASE/PKG.
450 .PP
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. 
455 .PP
456 .SH SPECIAL DEFINES
457 The 
458 .B TRACE
459 and
460 .B DEBUG
461 defines have a special meaning to the compiler.
462 .PP
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
467 .I "--define TRACE"
468 in the command line.
469 .PP
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
474 .I "--define DEBUG"
475 in the command line.
476 .PP
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.
479 .PP
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
485 .TP
486 .I "MCS_COLORS"
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.  
490 .Sp
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.
496 .Sp
497 The possible colors for background are: black, red, green, yellow,
498 blue, magenta, cyan, grey and white.
499 .Sp 
500 For example, you could set these variable from your shell:
501 .nf
502         export MCS_COLORS
503         MCS_COLORS=errors=brightwhite,red
504 .fi
505 .Sp
506 You can disable the built-in color scheme by setting this variable to
507 "disable".
508 .SH NOTES
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.  
514 .SH AUTHORS
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.
518 .PP
519 .SH LICENSE
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.
523 .PP
524 .SH SEE ALSO
525 csharp(1), mono(1), pkg-config(1), sn(1)
526 .PP
527 .SH BUGS
528 To report bugs in the compiler, you must file them on our bug tracking
529 system, at:
530 http://www.mono-project.com/community/bugs/
531 .SH MAILING LIST
532 The Mono Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/
533 .SH MORE INFORMATION
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
538 .PP
539 The home page for the Mono C# compiler is at http://www.mono-project.com/docs/about-mono/languages/csharp/