Merge pull request #3522 from henricm/fix-csharp-compiler-path-windows
[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 \-pkg:package1[,packageN]
242 Reference assemblies for the given packages.
243 .Sp
244 The compiler will invoke pkg-config --libs on the set of packages
245 specified on the command line to obtain libraries and directories to
246 compile the code.
247 .Sp
248 This is typically used with third party components, like this:
249 .nf
250
251                 $ mcs -pkg:gtk-sharp demo.cs
252 .fi
253 .RS
254 .ne 8
255 .TP
256 .I \-pkg:dotnet
257 This will instruct the compiler to reference the System.* libraries
258 available on a typical dotnet framework installation, notice that this
259 does not include all of the Mono libraries, only the System.* ones.  This
260 is a convenient shortcut for those porting code.
261 .ne
262 .RE
263 .TP
264 .I \-platform:ARCH
265 Used to specify the target platform. The possible values are: anycpu,
266 anycpu32bitpreferred, arm, x86, x64 or itanium. The default option is
267 anycpu.
268 .TP
269 .I -resource:RESOURCE[,ID]
270 Embeds to the given resource file.  The optional ID can be used to
271 give a different name to the resource.  If not specified, the resource
272 name will be the file name.
273 .TP
274 .I -linkresource:RESOURCE[,ID]
275 Links to the specified RESOURCE.  The optional ID can be used to give
276 a name to the linked resource.
277 .TP
278 .I -r:ASSEMBLY1[,ASSEMBLY2], \-reference ASSEMBLY1[,ASSEMBLY2]
279 Reference the named assemblies.  Use this to use classes from the named
280 assembly in your program.  The assembly will be loaded from either the
281 system directory where all the assemblies live, or from the path
282 explicitly given with the -L option.
283 .Sp
284 You can also use a semicolon to separate the assemblies instead of a
285 comma. 
286 .TP
287 .I -reference:ALIAS=ASSEMBLY
288 Extern alias reference support for C#.
289 .Sp
290 If you have different assemblies that provide the same types, the
291 extern alias support allows you to provide names that your software
292 can use to tell those appart.    The types from ASSEMBLY will be
293 exposed as ALIAS, then on the C# source code, you need to do:
294 .Sp
295 .nf
296         extern alias ALIAS;
297 .fi
298 To bring it into your namespace.   For example, to cope with two
299 graphics libraries that define "Graphics.Point", one in
300 "OpenGL.dll" and one in "Postscript.dll", you would invoke the
301 compiler like this:
302 .Sp
303 .nf
304         mcs -r:Postscript=Postscript.dll -r:OpenGL=OpenGL.dll
305 .fi
306 .Sp
307 And in your source code, you would write:
308 .Sp
309 .nf
310         extern alias Postscript;
311         extern alias OpenGL;
312
313         class X {
314                 // This is a Graphics.Point from Postscrip.dll
315                 Postscript.Point p = new Postscript.Point ();
316
317                 // This is a Graphics.Point from OpenGL.dll
318                 OpenGL.Point p = new OpenGL.Point ();
319         }
320 .fi
321 .TP
322 .I \-recurse:PATTERN, --recurse PATTERN
323 Does recursive compilation using the specified pattern.  In Unix the
324 shell will perform globbing, so you might want to use it like this:
325 .PP
326 .nf
327                 $ mcs -recurse:'*.cs' 
328 .fi
329 .TP
330 .I \-sdk:VERSION
331 Used to specify the version of Base Class Library assemblies used for
332 compilation. Following predefined values are valid: 2, 4 (default) as
333 well as any custom value. The predefined version number means which
334 .NET version should the produced assembly be compatible with. When
335 custom value is specified mcs will try to find Base Class Libraries
336 in the mono installed location PREFIX/lib/mono/<value>.
337 .TP
338 .I \-\-shell
339 Starts up the compiler in interactive mode, providing a C# shell for
340 statements and expressions.   A shortcut is to use the
341 .I csharp
342 command directly.
343 .TP
344 .I \-\-stacktrace
345 Generates a stack trace at the time the error is reported, useful for
346 debugging the compiler.
347 .TP
348 .I \-target:KIND, \-t:KIND
349 Used to specify the desired target.  The possible values are: exe
350 (plain executable), winexe (Windows.Forms executable), library
351 (component libraries) and module (partial library).
352 .TP
353 .I \-\-timestamp
354 Another debugging flag.  Used to display the times at various points
355 in the compilation process.
356 .TP
357 .I \-unsafe, -unsafe+
358 Enables compilation of unsafe code.
359 .TP
360 .I \-v 
361 Debugging. Turns on verbose yacc parsing.
362 .TP
363 .I \-\-version
364 Shows the compiler version.
365 .TP
366 .I \-warnaserror, \-warnaserror+
367 All compilers warnings will be reported as errors.
368 .TP
369 .I \-warnaserror:W1,[Wn], -warnaserror+:W1,[Wn]
370 Treats one or more compiler warnings as errors.
371 .TP
372 .I \-warnaserror-:W1,[Wn]
373 Sets one or more compiler warnings to be always threated as warnings.
374 Becomes useful when used together with -warnaserror.
375 .TP
376 .I \-warn:LEVEL
377 Sets the warning level.  0 is the lowest warning level, and 4 is the
378 highest.  The default is 4.
379 .TP
380 .I \-win32res:FILE
381 Specifies a Win32 resource file (.res) to be bundled into the
382 resulting assembly.
383 .TP
384 .I \-win32icon:FILE
385 Attaches the icon specified in FILE on the output into the resulting
386 assembly.
387 .TP
388 .I \-\-
389 Use this to stop option parsing, and allow option-looking parameters
390 to be passed on the command line.
391 .PP
392 .SH PACKAGES AND LIBRARIES
393 When referencing an assembly, if the name of the assembly is a path,
394 the compiler will try to load the assembly specified in the path.   If
395 it does not, then the compiler will try loading the assembly from the
396 current directory, the compiler base directory and if the assembly is
397 not found in any of those places in the directories specified as
398 arguments to the -lib: command argument.
399 .PP
400 The compiler uses the library path to locate libraries, and is able to
401 reference libraries from a particular package if that directory is
402 used.  To simplify the use of packages, the C# compiler includes the
403 -pkg: command line option that is used to load specific collections of
404 libraries. 
405 .PP 
406 Libraries visible to the compiler are stored relative to the
407 installation prefix under PREFIX/lib/mono/ called the PACKAGEBASE and the
408 defaults for mcs, gmcs and smcs are as follows:
409 .TP 
410 .I mcs
411 References the PACKAGEBASE/1.0 directory
412 .TP
413 .I gmcs
414 References the PACKAGEBASE/2.0 directory
415 .TP
416 .I smcs
417 References the PACKAGEBASE/2.1 directory
418 .PP
419 Those are the only runtime profiles that exist.  Although other
420 directories exist (like 3.0 and 3.5) those are not really runtime
421 profiles, they are merely placeholders for extra libraries that build
422 on the 2.0 foundation.
423 .PP
424 Software providers will distribute software that is installed relative
425 to the PACKAGEBASE directory.  This is integrated into the 
426 .I gacutil
427 tool that not only installs public assemblies into the Global Assembly
428 Cache (GAC) but also installs them into the PACKAGEBASE/PKG directory
429 (where PKG is the name passed to the -package flag to gacutil).
430 .PP
431 As a developer, if you want to consume the Gtk# libraries, you would
432 invoke the compiler like this:
433 .nf
434
435         $ mcs -pkg:gtk-sharp-2.0 main.cs
436
437 .fi
438 The -pkg: option instructs the compiler to fetch the definitions for
439 gtk-sharp-2.0 from pkg-config, this is equivalent to passing to the C#
440 compiler the output of:
441 .nf
442
443         $ pkg-config --libs gtk-sharp-2.0
444
445 .fi
446 Usually this merely references the libraries from PACKAGEBASE/PKG.
447 .PP
448 Although there are directory names for 3.0 and 3.5, that does not mean
449 that there are 3.0 and 3.5 compiler editions or profiles.   Those are
450 merely new libraries that must be manually referenced either with the
451 proper -pkg: invocation, or by referencing the libraries directly. 
452 .PP
453 .SH SPECIAL DEFINES
454 The 
455 .B TRACE
456 and
457 .B DEBUG
458 defines have a special meaning to the compiler.
459 .PP
460 By default calls to methods and properties in the
461 System.Diagnostics.Trace class are not generated unless the TRACE
462 symbol is defined (either through a "#define TRACE") in your source
463 code, or by using the
464 .I "--define TRACE"
465 in the command line.
466 .PP
467 By default calls to methods and properties in the
468 System.Diagnostics.Debug class are not generated unless the DEBUG
469 symbol is defined (either through a "#define DEBUG") in your source
470 code, or by using the
471 .I "--define DEBUG"
472 in the command line.
473 .PP
474 Note that the effect of defining TRACE and DEBUG is a global setting,
475 even if they are only defined in a single file.
476 .PP
477 .SH DEBUGGING SUPPORT
478 When using the "-debug" flag, MCS will generate a file with the
479 extension .mdb that contains the debugging information for the
480 generated assembly.  This file is consumed by the Mono debugger (mdb).
481 .SH ENVIRONMENT VARIABLES
482 .TP
483 .I "MCS_COLORS"
484 If this variable is set, it contains a string in the form
485 "foreground,background" that specifies which color to use to display
486 errors on some terminals.  
487 .Sp
488 The background is optional and defaults to your terminal current
489 background.   The possible colors for foreground are:
490 .B black, red, brightred, green, brightgreen, yellow, brightyellow,
491 blue, brightblue, magenta, brightmagenta, cyan, brightcyan, grey,
492 white and brightwhite.
493 .Sp
494 The possible colors for background are: black, red, green, yellow,
495 blue, magenta, cyan, grey and white.
496 .Sp 
497 For example, you could set these variable from your shell:
498 .nf
499         export MCS_COLORS
500         MCS_COLORS=errors=brightwhite,red
501 .fi
502 .Sp
503 You can disable the built-in color scheme by setting this variable to
504 "disable".
505 .SH NOTES
506 During compilation the MCS compiler defines the __MonoCS__ symbol,
507 this can be used by pre-processor instructions to compile Mono C#
508 compiler specific code.   Please note that this symbol is only to test
509 for the compiler, and is not useful to distinguish compilation or
510 deployment platforms.  
511 .SH AUTHORS
512 The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap,
513 Martin Baulig, Marek Safar and Raja Harinath.  The development was
514 funded by Ximian, Novell and Marek Safar.
515 .PP
516 .SH LICENSE
517 The Mono Compiler Suite is released under the terms of the GNU GPL or
518 the MIT X11.  Please read the accompanying `COPYING' file for details.
519 Alternative licensing for the compiler is available from Xamarin.
520 .PP
521 .SH SEE ALSO
522 csharp(1), mono(1), pkg-config(1), sn(1)
523 .PP
524 .SH BUGS
525 To report bugs in the compiler, you must file them on our bug tracking
526 system, at:
527 http://www.mono-project.com/community/bugs/
528 .SH MAILING LIST
529 The Mono Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/
530 .SH MORE INFORMATION
531 The Mono C# compiler was developed by Novell, Inc
532 (http://www.novell.com) and Xamarin Inc (http://www.xamarin.com) is based on the
533 ECMA C# language standard available here:
534 http://www.ecma.ch/ecma1/STAND/ecma-334.htm
535 .PP
536 The home page for the Mono C# compiler is at http://www.mono-project.com/docs/about-mono/languages/csharp/