Merge pull request #1496 from echampet/serializers
[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 and 4.0 specifications.
22 .PP
23 See the section on packages for more information.
24 .PP
25 The Mono C# compiler accepts the same command line options that the
26 Microsoft C# compiler does.  Those options can start with a slash or a
27 dash (/checked is the same as -checked).  Additionally some GNU-like
28 options are supported, those begin with "--".  All MCS-specific flags
29 which are not available in the Microsoft C# compiler are available
30 only with the GNU-style options.
31 .PP
32 C# source files must end with a ".cs" extension.  Compilation of C#
33 source code requires all the files that make up a library, module or
34 executable to be provided on the command line.  There is no support
35 for partial compilation.  To achieve the benefits of partial
36 compilation, you should compile programs into their own assemblies,
37 and later reference them with the "-r" flag.
38 .PP
39 The Mono C# compiler generates images (.exe files) that contain CIL
40 byte code that can be executed by any system that implements a Common
41 Language Infrastructure virtual machine such as the Microsoft .NET
42 runtime engine on Windows or the Mono runtime engine on Unix systems.
43 Executables are not bound to a specific CPU or operating system.
44 .PP
45 The Mono C# compiler by default only references three assemblies:
46 mscorlib.dll, System.dll and System.Xml.dll.   If you want to
47 reference extra libraries you must manually specify them using the
48 -pkg: command line option or the -r: command line option.
49 Alternatively if you want to get all of the System libraries, you can
50 use the -pkg:dotnet command line option.
51 .PP
52 .SH OPTIONS
53 .TP
54 .I \-\-about
55 Displays information about the Mono C# compiler
56 .TP
57 .I \-\-addmodule:MODULE1[,MODULE2]
58 Includes the specified modules in the resulting assembly.  Modules are
59 created by calling the compiler with the -target:module option
60 .TP
61 .I -checked, -checked+
62 Sets the default compilation mode to `checked'.  This makes all
63 the math operations checked (the default is unchecked).
64 .TP
65 .I -checked-
66 Sets the default compilation mode to `unchecked'.  This makes all
67 the math operations unchecked (this is the default).
68 .TP
69 .I -clscheck-, -clscheck+
70 Disables or enables the Common Language Specification (CLS) checks (it
71 is enabled by default). 
72 .Sp
73 The Common Language Specification (CLS) defines an interoperable
74 subset of types as well as conventions that compilers (CLS producers)
75 and developers must follow to expose code to other programming
76 languages (CLS consumers).  
77 .TP
78 .I -codepage:ID
79 Specifies the code page used to process the input files from the
80 point it is specified on.  By default files will be processed in the
81 environment-dependent native code page.  The compiler will also automatically
82 detect Unicode files that have an embedded byte mark at the beginning.   
83 .Sp
84 Other popular encodings are 28591 (Latin1), 1252 (iso-8859-1) and 65001 (UTF-8).
85 .Sp
86 MCS supports a couple of shorthands: "utf8" can be used to specify utf-8 instead
87 of using the cryptic 65001 and "reset" restores the automatic handling of
88 code pages.  These shorthands are not available on the Microsoft compiler.
89 .TP
90 .I \-define:SYMLIST, -d:SYMLIST
91 Defines the symbol listed by the semi-colon separated list SYMLIST
92 SYMBOL.  This can be tested in the source code by the pre-processor,
93 or can be used by methods that have been tagged with the Conditional
94 attribute. 
95 .TP
96 .I \-debug, \-debug+
97 Generate debugging information. To obtain stack traces with debugging
98 information, you need to invoke the mono runtime with the `--debug'
99 flag. The debugging information is stored in a MDB file located in
100 same output folder as produced assembly.
101 .TP
102 .I \-debug-
103 Do not generate debugging information.
104 .TP
105 .I \-delaysign+
106 Only embed the strongname public key into the assembly. The actual 
107 signing must be done in a later stage using the SN tool. This is useful
108 to protect the private key during development. Note that delay signing
109 can only be done using a strongname key file (not a key container). The
110 option is equivalent to including [assembly: AssemblyDelaySign (true)] 
111 in your source code. Compiler option takes precedence over the 
112 attributes.
113 .TP
114 .I \-delaysign-
115 Default. Strongname (sign) the assembly using the strong name key file
116 (or container). The option is equivalent to including [assembly: 
117 AssemblyDelaySign (false)] in your source code. Compiler option takes
118 precedence over the attributes.
119 .TP
120 .I \-doc:FILE
121 Extracts the C#/XML documentation from the source code and stores in in
122 the given FILE.
123 .TP
124 .I \-errorreport
125 This flag is ignored by Mono's C# compiler and is present only to
126 allow MCS to be used as a CSC replacement for msbuild/xbuild.
127 .TP
128 .I \-\-fatal 
129 This is used for debugging the compiler.  This makes the error emission
130 generate an exception that can be caught by a debugger.
131 .TP
132 .I \-filealign
133 This flag is ignored by Mono's C# compiler and is present only to
134 allow MCS to be used as a CSC replacement for msbuild/xbuild.
135 .TP
136 .I \-fullpaths
137 Any source code error or warning issued by the compiler includes file
138 name only by default. This option causes compiler to issue absolute file
139 path instead.
140 .TP
141 .I \-keyfile:KEYFILE
142 Strongname (sign) the output assembly using the key pair present in 
143 the specified strong name key file (snk). A full key pair is required
144 by default (or when using delaysign-). A file containing only the
145 public key can be used with delaysign+. The option is equivalent to 
146 including [assembly: AssemblyKeyFile ("KEYFILE")] in your source code.
147 Compiler option takes precedence over the attributes.
148 .TP
149 .I \-keycontainer:CONTAINER
150 Strongname (sign) the output assembly using the key pair present in 
151 the specified container. Note that delaysign+ is ignored when using 
152 key containers. The option is equivalent to including [assembly: 
153 AssemblyKeyName ("CONTAINER")] in your source code. Compiler option 
154 takes precedence over the attributes.
155 .TP
156 .I \-langversion:TEXT
157 The option specifies the version of the language to use. The feature
158 set is different in each C# version. This switch can be used to force
159 the compiler to allow only a subset of the features.
160 The possible values are:
161 .RS
162 .ne 8
163 .TP
164 .I "Default"
165 Instruct compiler to use the latest version. Equivalent is to omit the
166 switch (this currently defaults to the C# 4.0 language specification).
167 .TP
168 .I "ISO-1"
169 Restrict compiler to use only first ISO standardized features.
170 The usage of features such as generics, static classes, anonymous
171 methods will lead to error.
172 .TP
173 .I "ISO-2"
174 Restrict compiler to use only the second ISO standardized features.
175 This allows the use of generics, static classes, iterators and
176 anonymous methods for example.
177 .TP
178 .I "3"
179 Restrict the compiler to use only the features available in C# 3.0
180 (a superset of ISO-1 and ISO-2).
181 .TP
182 .I "4"
183 Restrict the compiler to use only the features available in C# 4.0
184 specification.
185 .TP
186 .I "future"
187 Enables unstable features from upcoming versions of the language.
188 .PP
189 Notice that this flag only restricts the language features available to
190 the programmer. A version of produced assemblies can be controled using
191 .I SDK
192 option.
193 .ne
194 .RE
195 .TP
196 .I -lib:PATHLIST
197 Each path specified in the comma-separated list will direct the
198 compiler to look for libraries in that specified path.
199 .TP
200 .I \-L PATH
201 Directs the compiler to look for libraries in the specified path.
202 Multiple paths can be provided by using the option multiple times.
203 .TP
204 .I \-main:CLASS
205 Tells the compiler which CLASS contains the entry point. Useful when
206 you are compiling several classes with a Main method.
207 .TP
208 .I \-nostdlib, -nostdlib+
209 Use this flag if you want to compile the core library.  This makes the
210 compiler load its internal types from the assembly being compiled.
211 .TP
212 .I \-noconfig, \-noconfig+
213 Disables the default compiler configuration to be loaded.  The
214 compiler by default has references to the system assemblies. 
215 .TP
216 .I \-nowarn:WARNLIST
217 Makes the compiler ignore warnings specified in the comma-separated
218 list WARNLIST>
219 .TP
220 .I -optimize, -optimize+, -optimize-
221 Controls compiler code generation optimizations on the code. Using -optimize or
222 -optimize+ will turn on optimizations, -optimize- will turn it off.
223 The default in mcs is to optimize-. The option can be mixed with -debug
224 but for the best debugging experience it is recommended leave the options off.
225 .TP
226 .I -out:FNAME, -o FNAME
227 Names the output file to be generated.
228 .TP
229 .I \-\-parse
230 Used for benchmarking.  The compiler will only parse its input files.
231 .TP
232 .I \-pkg:package1[,packageN]
233 Reference assemblies for the given packages.
234 .Sp
235 The compiler will invoke pkg-config --libs on the set of packages
236 specified on the command line to obtain libraries and directories to
237 compile the code.
238 .Sp
239 This is typically used with third party components, like this:
240 .nf
241
242                 $ mcs -pkg:gtk-sharp demo.cs
243 .fi
244 .RS
245 .ne 8
246 .TP
247 .I \-pkg:dotnet
248 This will instruct the compiler to reference the System.* libraries
249 available on a typical dotnet framework installation, notice that this
250 does not include all of the Mono libraries, only the System.* ones.  This
251 is a convenient shortcut for those porting code.
252 .TP
253 .I \-pkg:olive
254 Use this to reference the "Olive" libraries (the 3.0 and 3.5 extended
255 libraries).
256 .TP
257 .I \-pkg:silver
258 References the assemblies for creating Moonlight/Silverlight
259 applications.
260 .TP
261 .I \-pkg:silverdesktop
262 Use this option to create Moonlight/Silverlight applications that
263 target the desktop.   This option allows developers to consume the
264 Silverlight APIs with the full 2.0 profile API available to them,
265 unlike 
266 .I smcs 
267 it gives full access to all the APIs that are part of Mono.  The only
268 downside is that applications created with silverdesktop will not run
269 on the browser.   Typically these applications will be launched
270 with the 
271 .I mopen
272 command line tool.
273 .TP
274 For more details see the PACKAGE section in this document
275 .ne
276 .RE
277 .TP
278 .I \-platform:ARCH
279 Used to specify the target platform. The possible values are: anycpu,
280 anycpu32bitpreferred, arm, x86, x64 or itanium. The default option is
281 anycpu.
282 .TP
283 .I -resource:RESOURCE[,ID]
284 Embeds to the given resource file.  The optional ID can be used to
285 give a different name to the resource.  If not specified, the resource
286 name will be the file name.
287 .TP
288 .I -linkresource:RESOURCE[,ID]
289 Links to the specified RESOURCE.  The optional ID can be used to give
290 a name to the linked resource.
291 .TP
292 .I -r:ASSEMBLY1[,ASSEMBLY2], \-reference ASSEMBLY1[,ASSEMBLY2]
293 Reference the named assemblies.  Use this to use classes from the named
294 assembly in your program.  The assembly will be loaded from either the
295 system directory where all the assemblies live, or from the path
296 explicitly given with the -L option.
297 .Sp
298 You can also use a semicolon to separate the assemblies instead of a
299 comma. 
300 .TP
301 .I -reference:ALIAS=ASSEMBLY
302 Extern alias reference support for C#.
303 .Sp
304 If you have different assemblies that provide the same types, the
305 extern alias support allows you to provide names that your software
306 can use to tell those appart.    The types from ASSEMBLY will be
307 exposed as ALIAS, then on the C# source code, you need to do:
308 .Sp
309 .nf
310         extern alias ALIAS;
311 .fi
312 To bring it into your namespace.   For example, to cope with two
313 graphics libraries that define "Graphics.Point", one in
314 "OpenGL.dll" and one in "Postscript.dll", you would invoke the
315 compiler like this:
316 .Sp
317 .nf
318         mcs -r:Postscript=Postscript.dll -r:OpenGL=OpenGL.dll
319 .fi
320 .Sp
321 And in your source code, you would write:
322 .Sp
323 .nf
324         extern alias Postscript;
325         extern alias OpenGL;
326
327         class X {
328                 // This is a Graphics.Point from Postscrip.dll
329                 Postscript.Point p = new Postscript.Point ();
330
331                 // This is a Graphics.Point from OpenGL.dll
332                 OpenGL.Point p = new OpenGL.Point ();
333         }
334 .fi
335 .TP
336 .I \-recurse:PATTERN, --recurse PATTERN
337 Does recursive compilation using the specified pattern.  In Unix the
338 shell will perform globbing, so you might want to use it like this:
339 .PP
340 .nf
341                 $ mcs -recurse:'*.cs' 
342 .fi
343 .TP
344 .I \-sdk:VERSION
345 Used to specify the version of Base Class Library assemblies used for
346 compilation. Following predefined values are valid: 2, 4 (default) as
347 well as any custom value. The predefined version number means which
348 .NET version should the produced assembly be compatible with. When
349 custom value is specified mcs will try to find Base Class Libraries
350 in the mono installed location PREFIX/lib/mono/<value>.
351 .TP
352 .I \-\-shell
353 Starts up the compiler in interactive mode, providing a C# shell for
354 statements and expressions.   A shortcut is to use the
355 .I csharp
356 command directly.
357 .TP
358 .I \-\-stacktrace
359 Generates a stack trace at the time the error is reported, useful for
360 debugging the compiler.
361 .TP
362 .I \-target:KIND, \-t:KIND
363 Used to specify the desired target.  The possible values are: exe
364 (plain executable), winexe (Windows.Forms executable), library
365 (component libraries) and module (partial library).
366 .TP
367 .I \-\-timestamp
368 Another debugging flag.  Used to display the times at various points
369 in the compilation process.
370 .TP
371 .I \-unsafe, -unsafe+
372 Enables compilation of unsafe code.
373 .TP
374 .I \-v 
375 Debugging. Turns on verbose yacc parsing.
376 .TP
377 .I \-\-version
378 Shows the compiler version.
379 .TP
380 .I \-warnaserror, \-warnaserror+
381 All compilers warnings will be reported as errors.
382 .TP
383 .I \-warnaserror:W1,[Wn], -warnaserror+:W1,[Wn]
384 Treats one or more compiler warnings as errors.
385 .TP
386 .I \-warnaserror-:W1,[Wn]
387 Sets one or more compiler warnings to be always threated as warnings.
388 Becomes useful when used together with -warnaserror.
389 .TP
390 .I \-warn:LEVEL
391 Sets the warning level.  0 is the lowest warning level, and 4 is the
392 highest.  The default is 4.
393 .TP
394 .I \-win32res:FILE
395 Specifies a Win32 resource file (.res) to be bundled into the
396 resulting assembly.
397 .TP
398 .I \-win32icon:FILE
399 Attaches the icon specified in FILE on the output into the resulting
400 assembly.
401 .TP
402 .I \-\-
403 Use this to stop option parsing, and allow option-looking parameters
404 to be passed on the command line.
405 .PP
406 .SH PACKAGES AND LIBRARIES
407 When referencing an assembly, if the name of the assembly is a path,
408 the compiler will try to load the assembly specified in the path.   If
409 it does not, then the compiler will try loading the assembly from the
410 current directory, the compiler base directory and if the assembly is
411 not found in any of those places in the directories specified as
412 arguments to the -lib: command argument.
413 .PP
414 The compiler uses the library path to locate libraries, and is able to
415 reference libraries from a particular package if that directory is
416 used.  To simplify the use of packages, the C# compiler includes the
417 -pkg: command line option that is used to load specific collections of
418 libraries. 
419 .PP 
420 Libraries visible to the compiler are stored relative to the
421 installation prefix under PREFIX/lib/mono/ called the PACKAGEBASE and the
422 defaults for mcs, gmcs and smcs are as follows:
423 .TP 
424 .I mcs
425 References the PACKAGEBASE/1.0 directory
426 .TP
427 .I gmcs
428 References the PACKAGEBASE/2.0 directory
429 .TP
430 .I smcs
431 References the PACKAGEBASE/2.1 directory
432 .PP
433 Those are the only runtime profiles that exist.  Although other
434 directories exist (like 3.0 and 3.5) those are not really runtime
435 profiles, they are merely placeholders for extra libraries that build
436 on the 2.0 foundation.
437 .PP
438 Software providers will distribute software that is installed relative
439 to the PACKAGEBASE directory.  This is integrated into the 
440 .I gacutil
441 tool that not only installs public assemblies into the Global Assembly
442 Cache (GAC) but also installs them into the PACKAGEBASE/PKG directory
443 (where PKG is the name passed to the -package flag to gacutil).
444 .PP
445 As a developer, if you want to consume the Gtk# libraries, you would
446 invoke the compiler like this:
447 .nf
448
449         $ mcs -pkg:gtk-sharp-2.0 main.cs
450
451 .fi
452 The -pkg: option instructs the compiler to fetch the definitions for
453 gtk-sharp-2.0 from pkg-config, this is equivalent to passing to the C#
454 compiler the output of:
455 .nf
456
457         $ pkg-config --libs gtk-sharp-2.0
458
459 .fi
460 Usually this merely references the libraries from PACKAGEBASE/PKG.
461 .PP
462 Although there are directory names for 3.0 and 3.5, that does not mean
463 that there are 3.0 and 3.5 compiler editions or profiles.   Those are
464 merely new libraries that must be manually referenced either with the
465 proper -pkg: invocation, or by referencing the libraries directly. 
466 .PP
467 .SH SPECIAL DEFINES
468 The 
469 .B TRACE
470 and
471 .B DEBUG
472 defines have a special meaning to the compiler.
473 .PP
474 By default calls to methods and properties in the
475 System.Diagnostics.Trace class are not generated unless the TRACE
476 symbol is defined (either through a "#define TRACE") in your source
477 code, or by using the
478 .I "--define TRACE"
479 in the command line.
480 .PP
481 By default calls to methods and properties in the
482 System.Diagnostics.Debug class are not generated unless the DEBUG
483 symbol is defined (either through a "#define DEBUG") in your source
484 code, or by using the
485 .I "--define DEBUG"
486 in the command line.
487 .PP
488 Note that the effect of defining TRACE and DEBUG is a global setting,
489 even if they are only defined in a single file.
490 .PP
491 .SH DEBUGGING SUPPORT
492 When using the "-debug" flag, MCS will generate a file with the
493 extension .mdb that contains the debugging information for the
494 generated assembly.  This file is consumed by the Mono debugger (mdb).
495 .SH ENVIRONMENT VARIABLES
496 .TP
497 .I "MCS_COLORS"
498 If this variable is set, it contains a string in the form
499 "foreground,background" that specifies which color to use to display
500 errors on some terminals.  
501 .Sp
502 The background is optional and defaults to your terminal current
503 background.   The possible colors for foreground are:
504 .B black, red, brightred, green, brightgreen, yellow, brightyellow,
505 blue, brightblue, magenta, brightmagenta, cyan, brightcyan, grey,
506 white and brightwhite.
507 .Sp
508 The possible colors for background are: black, red, green, yellow,
509 blue, magenta, cyan, grey and white.
510 .Sp 
511 For example, you could set these variable from your shell:
512 .nf
513         export MCS_COLORS
514         MCS_COLORS=errors=brightwhite,red
515 .fi
516 .Sp
517 You can disable the built-in color scheme by setting this variable to
518 "disable".
519 .SH NOTES
520 During compilation the MCS compiler defines the __MonoCS__ symbol,
521 this can be used by pre-processor instructions to compile Mono C#
522 compiler specific code.   Please note that this symbol is only to test
523 for the compiler, and is not useful to distinguish compilation or
524 deployment platforms.  
525 .SH AUTHORS
526 The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap,
527 Martin Baulig, Marek Safar and Raja Harinath.  The development was
528 funded by Ximian, Novell and Marek Safar.
529 .PP
530 .SH LICENSE
531 The Mono Compiler Suite is released under the terms of the GNU GPL or
532 the MIT X11.  Please read the accompanying `COPYING' file for details.
533 Alternative licensing for the compiler is available from Xamarin.
534 .PP
535 .SH SEE ALSO
536 csharp(1), mdb(1), mono(1), mopen(1), pkg-config(1), sn(1)
537 .PP
538 .SH BUGS
539 To report bugs in the compiler, you must file them on our bug tracking
540 system, at:
541 http://www.mono-project.com/community/bugs/
542 .SH MAILING LIST
543 The Mono Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/
544 .SH MORE INFORMATION
545 The Mono C# compiler was developed by Novell, Inc
546 (http://www.novell.com) and Xamarin Inc (http://www.xamarin.com) is based on the
547 ECMA C# language standard available here:
548 http://www.ecma.ch/ecma1/STAND/ecma-334.htm
549 .PP
550 The home page for the Mono C# compiler is at http://www.mono-project.com/docs/about-mono/languages/csharp/