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