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