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

NAME

6       mcs - Mono C# Compiler
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 latest Mono Base Class
19       Library version and fully implements C# 1.0, 2.0, 3.0 and 4.0  specifi‐
20       cations.
21
22       See the section on packages for more information.
23
24       The Mono C# compiler accepts the same command line options that the Mi‐
25       crosoft C# compiler does.  Those options can start with a  slash  or  a
26       dash  (/checked  is  the same as -checked).  Additionally some GNU-like
27       options are supported, those begin with "--".  All  MCS-specific  flags
28       which are not available in the Microsoft C# compiler are available only
29       with the GNU-style options.
30
31       C# source files must end with a ".cs"  extension.   Compilation  of  C#
32       source  code  requires  all the files that make up a library, module or
33       executable to be provided on the command line.  There is no support for
34       partial  compilation.   To achieve the benefits of partial compilation,
35       you should compile programs into their own assemblies, and later refer‐
36       ence them with the "-r" flag.
37
38       The  Mono  C#  compiler  generates images (.exe files) that contain CIL
39       byte code that can be executed by any system that implements  a  Common
40       Language Infrastructure virtual machine such as the Microsoft .NET run‐
41       time engine on Windows or the Mono  runtime  engine  on  Unix  systems.
42       Executables are not bound to a specific CPU or operating system.
43
44       The  Mono  C#  compiler  by  default  only references three assemblies:
45       mscorlib.dll, System.dll and System.Xml.dll.   If you want to reference
46       extra  libraries you must manually specify them using the -pkg: command
47       line option or the -r: command line option.  Alternatively if you  want
48       to get all of the System libraries, you can use the -pkg:dotnet command
49       line option.
50

OPTIONS

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

PACKAGES AND LIBRARIES

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

SPECIAL DEFINES

423       The TRACE and DEBUG defines have a special meaning to the compiler.
424
425       By default calls to  methods  and  properties  in  the  System.Diagnos‐
426       tics.Trace  class  are not generated unless the TRACE symbol is defined
427       (either through a "#define TRACE") in your source code, or by using the
428       --define TRACE in the command line.
429
430       By  default  calls  to  methods  and  properties in the System.Diagnos‐
431       tics.Debug class are not generated unless the DEBUG symbol  is  defined
432       (either through a "#define DEBUG") in your source code, or by using the
433       --define DEBUG in the command line.
434
435       Note that the effect of defining TRACE and DEBUG is a  global  setting,
436       even if they are only defined in a single file.
437

DEBUGGING SUPPORT

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

ENVIRONMENT VARIABLES

444       MCS_COLORS
445              If this variable is set, it contains a string in the form "fore‐
446              ground,background" that specifies which color to use to  display
447              errors on some terminals.
448
449              The background is optional and defaults to your terminal current
450              background.   The possible colors  for  foreground  are:  black,
451              red,  brightred, green, brightgreen, yellow, brightyellow, blue,
452              brightblue,  magenta,  brightmagenta,  cyan,  brightcyan,  grey,
453              white and brightwhite.
454
455              The  possible colors for background are: black, red, green, yel‐
456              low, blue, magenta, cyan, grey and white.
457
458              For example, you could set these variable from your shell:
459                   export MCS_COLORS
460                   MCS_COLORS=errors=brightwhite,red
461
462              You can disable the built-in color scheme by setting this  vari‐
463              able to "disable".
464

NOTES

466       During compilation the MCS compiler defines the __MonoCS__ symbol, this
467       can be used by pre-processor instructions to compile Mono  C#  compiler
468       specific  code.    Please note that this symbol is only to test for the
469       compiler, and is not useful to distinguish  compilation  or  deployment
470       platforms.
471

AUTHORS

473       The  Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap, Mar‐
474       tin Baulig, Marek Safar and Raja Harinath.  The development was  funded
475       by Ximian, Novell and Marek Safar.
476

LICENSE

478       The  Mono  Compiler Suite is released under the terms of the GNU GPL or
479       the MIT X11.  Please read the accompanying `COPYING' file for  details.
480       Alternative licensing for the compiler is available from Xamarin.
481

SEE ALSO

483       csharp(1), mdb(1), mono(1), mopen(1), pkg-config(1), sn(1)
484

BUGS

486       To  report bugs in the compiler, you must file them on our bug tracking
487       system, at: http://www.mono-project.com/community/bugs/
488

MAILING LIST

490       The Mono Mailing lists are listed at http://www.mono-project.com/commu
491       nity/help/mailing-lists/
492

MORE INFORMATION

494       The  Mono  C#  compiler  was  developed by Novell, Inc (http://www.nov
495       ell.com) and Xamarin Inc (http://www.xamarin.com) is based on the  ECMA
496       C#          language          standard          available         here:
497       http://www.ecma.ch/ecma1/STAND/ecma-334.htm
498
499       The  home  page  for  the  Mono  C#  compiler  is  at  http://www.mono-
500       project.com/docs/about-mono/languages/csharp/
501
502
503
504                                6 January 2001                          mcs(1)
Impressum