1mcs(1)                      General Commands Manual                     mcs(1)
2
3
4

NAME

6       mcs, gmcs, smcs - Mono C# Compiler (1.0, 2.0, Moonlight)
7

SYNOPSIS

9       mcs [option] [source-files]
10

DESCRIPTION

12       mcs is the Mono C# compiler, an implementation of the ECMA-334 language
13       specification.  You can pass one or more options to drive the compiler,
14       and  a set of source files.  Extra options or arguments can be provided
15       in a response file.  Response files are referenced by prepending the  @
16       symbol to the response file name.
17
18       The  mcs compiler is used to compile against the 1.x profile and imple‐
19       ments C# 1.0 and parts of C# 2.0 and C# 3.0 specification which do  not
20       depend on generics.
21
22       The gmcs compiler is used to compile against the 2.0 profile and imple‐
23       ments the complete C# 3.0 specification.
24
25       The smcs compiler is used to compile against the  Silverlight/Moonlight
26       profile.   This  profile  is  designed  to  be  used  for creating Sil‐
27       verlight/Moonlight applications that will run on a web  browser.    The
28       API  exposed  by this profile is a small subset of the 3.5 API (even if
29       it is commonly referred as the 2.1 API, this API is a small  subset  of
30       2.0 with a few extensions).
31
32       See the section on packages for more information.
33
34       The Mono C# compiler accepts the same command line options that the Mi‐
35       crosoft C# compiler does.  Those options can start with a  slash  or  a
36       dash  (/checked  is  the same as -checked).  Additionally some GNU-like
37       options are supported, those begin with "--".  All  MCS-specific  flags
38       which are not available in the Microsoft C# compiler are available only
39       with the GNU-style options.
40
41       C# source files must end with a ".cs"  extension.   Compilation  of  C#
42       source  code  requires  all the files that make up a library, module or
43       executable to be provided on the command line.  There is no support for
44       partial  compilation.   To achieve the benefits of partial compilation,
45       you should compile programs into their own assemblies, and later refer‐
46       ence them with the "-r" flag.
47
48       The  Mono  C#  compiler  generates images (.exe files) that contain CIL
49       byte code that can be executed by any system that implements  a  Common
50       Language Infrastructure virtual machine such as the Microsoft .NET run‐
51       time engine on Windows or the Mono  runtime  engine  on  Unix  systems.
52       Executables are not bound to a specific CPU or operating system.
53
54       The  Mono  C#  compiler  by  default  only references three assemblies:
55       mscorlib.dll, System.dll and System.Xml.dll.   If you want to reference
56       extra  libraries you must manually specify them using the -pkg: command
57       line option or the -r: command line option.  Alternatively if you  want
58       to get all of the System libraries, you can use the -pkg:dotnet command
59       line option.
60

OPTIONS

62       --about
63              Displays information about the Mono C# compiler
64
65       --addmodule:MODULE1[,MODULE2]
66              Includes the specified modules in the resulting assembly.   Mod‐
67              ules are created by calling the compiler with the -target:module
68              option
69
70       -checked, -checked+
71              Sets the default compilation mode to `checked'.  This makes  all
72              the math operations checked (the default is unchecked).
73
74       -checked-
75              Sets  the  default  compilation mode to `unchecked'.  This makes
76              all the math operations unchecked (this is the default).
77
78       -clscheck-, -clscheck+
79              Disables or enables  the  Common  Language  Specification  (CLS)
80              checks (it is enabled by default).
81
82              The Common Language Specification (CLS) defines an interoperable
83              subset of types as well as conventions that compilers (CLS  pro‐
84              ducers)  and developers must follow to expose code to other pro‐
85              gramming languages (CLS consumers).
86
87       -codepage:ID
88              Specifies the code page used to process the input files from the
89              point it is specified on.  By default files will be processed in
90              the environment-dependent native code page.  The  compiler  will
91              also  automatically  detect  Unicode files that have an embedded
92              byte mark at the beginning.
93
94              Other popular encodings are 28591  (Latin1),  1252  (iso-8859-1)
95              and 65001 (UTF-8).
96
97              MCS supports a couple of shorthands: "utf8" can be used to spec‐
98              ify utf-8  instead  of  using  the  cryptic  65001  and  "reset"
99              restores the automatic handling of code pages.  These shorthands
100              are not available on the Microsoft compiler.
101
102       -define:SYMLIST, -d:SYMLIST
103              Defines the symbol listed by the semi-colon separated list  SYM‐
104              LIST  SYMBOL.  This can be tested in the source code by the pre-
105              processor, or can be used by methods that have been tagged  with
106              the Conditional attribute.
107
108       -debug, -debug+
109              Generate  debugging  information.   To  obtain stack traces with
110              debugging information, you need to invoke the mono runtime  with
111              the `--debug' flag.  This debugging information is stored inside
112              the assembly as a resource.
113
114       -debug-
115              Do not generate debugging information.
116
117       -delaysign+
118              Only embed the strongname public  key  into  the  assembly.  The
119              actual  signing must be done in a later stage using the SN tool.
120              This is useful to protect the private  key  during  development.
121              Note  that delay signing can only be done using a strongname key
122              file (not a key container). The option is equivalent to  includ‐
123              ing  [assembly:  AssemblyDelaySign  (true)] in your source code.
124              Compiler option takes precedence over the attributes.
125
126       -delaysign-
127              Default. Strongname (sign) the assembly using  the  strong  name
128              key  file  (or container). The option is equivalent to including
129              [assembly: AssemblyDelaySign (false)] in your source code.  Com‐
130              piler option takes precedence over the attributes.
131
132       -doc:FILE
133              Extracts  the  C#/XML  documentation  from  the  source code and
134              stores in in the given FILE.
135
136       -errorreport
137              This flag is ignored by Mono's C# compiler and is  present  only
138              to allow MCS to be used as a CSC replacement for msbuild/xbuild.
139
140       --fatal
141              This  is  used for debugging the compiler.  This makes the error
142              emission generate an exception that can be caught by a debugger.
143
144       -filealign
145              This flag is ignored by Mono's C# compiler and is  present  only
146              to allow MCS to be used as a CSC replacement for msbuild/xbuild.
147
148       -keyfile:KEYFILE
149              Strongname (sign) the output assembly using the key pair present
150              in the specified strong name key file (snk). A full key pair  is
151              required  by default (or when using delaysign-). A file contain‐
152              ing only the public key can be used with delaysign+. The  option
153              is  equivalent  to  including  [assembly: AssemblyKeyFile ("KEY‐
154              FILE")] in your source code.  Compiler option  takes  precedence
155              over the attributes.
156
157       -keycontainer:CONTAINER
158              Strongname (sign) the output assembly using the key pair present
159              in the specified container. Note that delaysign+ is ignored when
160              using  key  containers.  The  option  is equivalent to including
161              [assembly: AssemblyKeyName ("CONTAINER")] in your  source  code.
162              Compiler option takes precedence over the attributes.
163
164       -langversion:TEXT
165              The  option  specifies  the  version of the language to use. The
166              feature set is different in each C# version. This switch can  be
167              used  to  force  the compiler to allow only a subset of the fea‐
168              tures.  The possible values are:
169
170              Default
171                     Instruct compiler to use the latest  version.  Equivalent
172                     is  to omit the switch (this currently defaults to the C#
173                     3.0 language specification).
174
175              ISO-1  Restrict compiler to use only first ISO standardized fea‐
176                     tures.   The  usage  of features such as generics, static
177                     classes, anonymous methods will lead to error.
178
179              ISO-2  Restrict compiler to use only the second ISO standardized
180                     features.   This  allows  the  use  of  generics,  static
181                     classes, iterators and anonymous methods for example.
182
183              3      Restrict the compiler to use only the features  available
184                     in C# 3.0 (a superset of ISO-1 and ISO-2).
185
186              future Enables  features from upcoming versions of the language.
187                     As of May 2009 this includes support for C# 4 as released
188                     in Visual Studio 2010 beta 1.
189
190              Notice that this flag only controls the language features avail‐
191              able to the programmer, it does not control the kind  of  assem‐
192              blies  produced.   Programs compiled with mcs will reference the
193              1.1 APIs, Programs compiled with gmcs reference the 2.0 APIs.
194
195       -lib:PATHLIST
196              Each path specified in the comma-separated list will direct  the
197              compiler to look for libraries in that specified path.
198
199       -L PATH
200              Directs  the  compiler  to  look  for libraries in the specified
201              path.  Multiple paths can be provided by using the option multi‐
202              ple times.
203
204       -main:CLASS
205              Tells  the compiler which CLASS contains the entry point. Useful
206              when you are compiling several classes with a Main method.
207
208       -nostdlib, -nostdlib+
209              Use this flag if you want to compile  the  core  library.   This
210              makes  the  compiler  load  its internal types from the assembly
211              being compiled.
212
213       -noconfig, -noconfig+
214              Disables the default compiler configuration to be  loaded.   The
215              compiler by default has references to the system assemblies.
216
217       -nowarn:WARNLIST
218              Makes  the compiler ignore warnings specified in the comma-sepa‐
219              rated list WARNLIST>
220
221       -optimize, -optimize+, -optimize-
222              Controls whether to perform optimizations on the code.    -opti‐
223              mize  and -optimize+ will turn on optimizations, -optimize- will
224              turn it off.  The default in mcs is to optimize+.
225
226       -out:FNAME, -o FNAME
227              Names the output file to be generated.
228
229       --parse
230              Used for benchmarking.  The compiler will only parse  its  input
231              files.
232
233       -pkg:package1[,packageN]
234              Reference assemblies for the given packages.
235
236              The  compiler  will invoke pkg-config --libs on the set of pack‐
237              ages specified on the  command  line  to  obtain  libraries  and
238              directories to compile the code.
239
240              This is typically used with third party components, like this:
241
242                        $ mcs -pkg:gtk-sharp demo.cs
243
244              -pkg:dotnet
245                     This will instruct the compiler to reference the System.*
246                     libraries available on a typical dotnet framework instal‐
247                     lation, notice that this does not include all of the Mono
248                     libraries, only the System.* ones.  This is a  convenient
249                     shortcut for those porting code.
250
251              -pkg:olive
252                     Use  this to reference the "Olive" libraries (the 3.0 and
253                     3.5 extended libraries).
254
255              -pkg:silver
256                     References the  assemblies  for  creating  Moonlight/Sil‐
257                     verlight  applications.   This is automatically used when
258                     using the smcs compiler, but it is here  when  developers
259                     want to use it with the gmcs compiler.
260
261              -pkg:silverdesktop
262                     Use  this option to create Moonlight/Silverlight applica‐
263                     tions that  target  the  desktop.    This  option  allows
264                     developers  to consume the Silverlight APIs with the full
265                     2.0 profile API available to them, unlike smcs  it  gives
266                     full  access  to all the APIs that are part of Mono.  The
267                     only downside is  that  applications  created  with  sil‐
268                     verdesktop will not run on the browser.   Typically these
269                     applications will be launched with the mopen command line
270                     tool.
271
272              For more details see the PACKAGE section in this document
273
274       -platform:ARCH
275              Used  to  specify  the target platform. The possible values are:
276              anycpu, x86, x64 or itanium. As of June 2009, the  Mono  runtime
277              only have support to emit anycpu and x86 assemblies.
278
279       -resource:RESOURCE[,ID]
280              Embeds  to the given resource file.  The optional ID can be used
281              to give a different name to the resource.  If not specified, the
282              resource name will be the file name.
283
284       -linkresource:RESOURCE[,ID]
285              Links to the specified RESOURCE.  The optional ID can be used to
286              give a name to the linked resource.
287
288       -r:ASSEMBLY1[,ASSEMBLY2], -reference ASSEMBLY1[,ASSEMBLY2]
289              Reference the named assemblies.  Use this to  use  classes  from
290              the named assembly in your program.  The assembly will be loaded
291              from either the system directory where all the assemblies  live,
292              or from the path explicitly given with the -L option.
293
294              You  can also use a semicolon to separate the assemblies instead
295              of a comma.
296
297       -reference:ALIAS=ASSEMBLY
298              Extern alias reference support for C#.
299
300              If you have different assemblies that provide  the  same  types,
301              the  extern  alias support allows you to provide names that your
302              software can use to tell those appart.    The types from  ASSEM‐
303              BLY  will  be  exposed as ALIAS, then on the C# source code, you
304              need to do:
305
306                   extern alias ALIAS;
307              To bring it into your namespace.   For example, to cope with two
308              graphics   libraries   that   define  "Graphics.Point",  one  in
309              "OpenGL.dll" and one in "Postscript.dll", you would  invoke  the
310              compiler like this:
311
312                   mcs -r:Postscript=Postscript.dll -r:OpenGL=OpenGL.dll
313
314              And in your source code, you would write:
315
316                   extern alias Postscript;
317                   extern alias OpenGL;
318
319                   class X {
320                        // This is a Graphics.Point from Postscrip.dll
321                        Postscript.Point p = new Postscript.Point ();
322
323                        // This is a Graphics.Point from OpenGL.dll
324                        OpenGL.Point p = new OpenGL.Point ();
325                   }
326
327       -recurse:PATTERN, --recurse PATTERN
328              Does recursive compilation using the specified pattern.  In Unix
329              the shell will perform globbing, so you might  want  to  use  it
330              like this:
331
332                 $ mcs -recurse:'*.cs'
333
334       --shell
335              Starts up the compiler in interactive mode, providing a C# shell
336              for statements and expressions.    A  shortcut  is  to  use  the
337              csharp command directly.
338
339       --stacktrace
340              Generates  a stack trace at the time the error is reported, use‐
341              ful for debugging the compiler.
342
343       -target:KIND, -t:KIND
344              Used to specify the desired target.  The  possible  values  are:
345              exe   (plain  executable),  winexe  (Windows.Forms  executable),
346              library (component libraries) and module (partial library).
347
348       --timestamp
349              Another debugging flag.  Used to display the  times  at  various
350              points in the compilation process.
351
352       -unsafe, -unsafe+
353              Enables compilation of unsafe code.
354
355       -v     Debugging. Turns on verbose yacc parsing.
356
357       --version
358              Shows the compiler version.
359
360       -warnaserror, -warnaserror+
361              All compilers warnings will be reported as errors.
362
363       -warnaserror:W1,[Wn], -warnaserror+:W1,[Wn]
364              Treats one or more compiler warnings as errors.
365
366       -warnaserror-:W1,[Wn]
367              Sets  one  or  more  compiler  warnings to be always threated as
368              warnings.  Becomes useful when used together with -warnaserror.
369
370       -warn:LEVEL
371              Sets the warning level.  0 is the lowest warning level, and 4 is
372              the highest.  The default is 4.
373
374       -win32res:FILE
375              Specifies  a  Win32  resource file (.res) to be bundled into the
376              resulting assembly.
377
378       -win32icon:FILE
379              Attaches the icon specified in  FILE  on  the  output  into  the
380              resulting assembly.
381
382       --     Use this to stop option parsing, and allow option-looking param‐
383              eters to be passed on the command line.
384

PACKAGES AND LIBRARIES

386       When referencing an assembly, if the name of the assembly  is  a  path,
387       the  compiler will try to load the assembly specified in the path.   If
388       it does not, then the compiler will try loading the assembly  from  the
389       current  directory,  the compiler base directory and if the assembly is
390       not found in any of those places in the directories specified as  argu‐
391       ments to the -lib: command argument.
392
393       Depending  on  the  invocation for the C# compiler (mcs, gmcs, or smcs)
394       you will get a default set of libraries and versions of those libraries
395       that are referenced.
396
397       The  compiler uses the library path to locate libraries, and is able to
398       reference libraries from a particular  package  if  that  directory  is
399       used.   To  simplify  the use of packages, the C# compiler includes the
400       -pkg: command line option that is used to load specific collections  of
401       libraries.
402
403       Libraries  visible to the compiler are stored relative to the installa‐
404       tion prefix under  PREFIX/lib/mono/  called  the  PACKAGEBASE  and  the
405       defaults for mcs, gmcs and smcs are as follows:
406
407       mcs    References the PACKAGEBASE/1.0 directory
408
409       gmcs   References the PACKAGEBASE/2.0 directory
410
411       smcs   References the PACKAGEBASE/2.1 directory
412
413       Those  are the only runtime profiles that exist.  Although other direc‐
414       tories exist (like 3.0 and 3.5) those are not really runtime  profiles,
415       they  are merely placeholders for extra libraries that build on the 2.0
416       foundation.
417
418       Software providers will distribute software that is installed  relative
419       to the PACKAGEBASE directory.  This is integrated into the gacutil tool
420       that not only installs public assemblies into the Global Assembly Cache
421       (GAC)  but also installs them into the PACKAGEBASE/PKG directory (where
422       PKG is the name passed to the -package flag to gacutil).
423
424       As a developer, if you want to consume the Gtk#  libraries,  you  would
425       invoke the compiler like this:
426
427            $ mcs -pkg:gtk-sharp-2.0 main.cs
428
429       The  -pkg:  option  instructs the compiler to fetch the definitions for
430       gtk-sharp-2.0 from pkg-config, this is equivalent to passing to the  C#
431       compiler the output of:
432
433            $ pkg-config --libs gtk-sharp-2.0
434
435       Usually this merely references the libraries from PACKAGEBASE/PKG.
436
437       Although  there are directory names for 3.0 and 3.5, that does not mean
438       that there are 3.0 and 3.5 compiler editions or profiles.    Those  are
439       merely  new  libraries that must be manually referenced either with the
440       proper -pkg: invocation, or by referencing the libraries directly.
441

SPECIAL DEFINES

443       The TRACE and DEBUG defines have a special meaning to the compiler.
444
445       By default calls to  methods  and  properties  in  the  System.Diagnos‐
446       tics.Trace  class  are not generated unless the TRACE symbol is defined
447       (either through a "#define TRACE") in your source code, or by using the
448       --define TRACE in the command line.
449
450       By  default  calls  to  methods  and  properties in the System.Diagnos‐
451       tics.Debug class are not generated unless the DEBUG symbol  is  defined
452       (either through a "#define DEBUG") in your source code, or by using the
453       --define DEBUG in the command line.
454
455       Note that the effect of defining TRACE and DEBUG is a  global  setting,
456       even if they are only defined in a single file.
457

DEBUGGING SUPPORT

459       When  using the "-debug" flag, MCS will generate a file with the exten‐
460       sion .mdb that contains the debugging  information  for  the  generated
461       assembly.  This file is consumed by the Mono debugger (mdb).
462

ENVIRONMENT VARIABLES

464       MCS_COLORS
465              If this variable is set, it contains a string in the form "fore‐
466              ground,background" that specifies which color to use to  display
467              errors on some terminals.
468
469              The background is optional and defaults to your terminal current
470              background.   The possible colors  for  foreground  are:  black,
471              red,  brightred, green, brightgreen, yellow, brightyellow, blue,
472              brightblue,  magenta,  brightmagenta,  cyan,  brightcyan,  grey,
473              white and brightwhite.
474
475              The  possible colors for background are: black, red, green, yel‐
476              low, blue, magenta, cyan, grey and white.
477
478              For example, you could set these variable from your shell:
479                   export MCS_COLORS
480                   MCS_COLORS=errors=brightwhite,red
481
482              You can disable the built-in color scheme by setting this  vari‐
483              able to "disable".
484

NOTES

486       During compilation the MCS compiler defines the __MonoCS__ symbol, this
487       can be used by pre-processor instructions to compile Mono  C#  compiler
488       specific  code.    Please note that this symbol is only to test for the
489       compiler, and is not useful to distinguish  compilation  or  deployment
490       platforms.
491

AUTHORS

493       The  Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap, Mar‐
494       tin Baulig, Marek Safar and Raja Harinath.  The development was  funded
495       by Ximian, Novell and Marek Safar.
496

LICENSE

498       The  Mono  Compiler Suite is released under the terms of the GNU GPL or
499       the MIT X11.  Please read the accompanying `COPYING' file for  details.
500       Alternative licensing for the compiler is available from Novell.
501

SEE ALSO

503       csharp(1), mdb(1), mono(1), mopen(1), mint(1), pkg-config(1),sn(1)
504

BUGS

506       To  report bugs in the compiler, you must file them on our bug tracking
507       system, at: http://www.mono-project.com/Bugs
508

MAILING LIST

510       The Mono Mailing lists are listed at  http://www.mono-project.com/Mail
511       ing_Lists
512

MORE INFORMATION

514       The  Mono  C#  compiler  was  developed by Novell, Inc (http://www.nov
515       ell.com, http) and is based on the ECMA C# language standard  available
516       here: http://www.ecma.ch/ecma1/STAND/ecma-334.htm
517
518       The  home  page  for  the  Mono  C#  compiler  is  at  http://www.mono-
519       project.com/CSharp_Compiler
520
521
522
523                                6 January 2001                          mcs(1)
Impressum