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

NAME

6       mcs - Turbo C# Compiler
7

SYNOPSIS

9       mcs [option] [source-files]
10

DESCRIPTION

12       mcs  is  the Turbo C# compiler (also known as the Mono C# compiler), it
13       is an implementation of the ECMA-334 language specification.   You  can
14       pass  one  or  more  options to drive the compiler, and a set of source
15       files.  Extra options or arguments can be provided in a response  file.
16       Response  files  are  referenced  by  prepending  the  @  symbol to the
17       response file name.
18
19       The mcs compiler is used to compile against the latest Mono Base  Class
20       Library version and fully implements C# 1.0, 2.0, 3.0, 4.0, 5.0 and 6.0
21       specifications with partial support for C# 7.0.
22
23       See the section on packages for more information.
24
25       The Turbo C# compiler accepts the same command line  options  that  the
26       Microsoft  C# compiler does.  Those options can start with a slash or a
27       dash (/checked is the same as -checked).   Additionally  some  GNU-like
28       options  are  supported, those begin with "--".  All MCS-specific flags
29       which are not available in the Microsoft C# compiler are available only
30       with the GNU-style options.
31
32       C#  source  files  must  end with a ".cs" extension.  Compilation of C#
33       source code requires all the files that make up a  library,  module  or
34       executable to be provided on the command line.  There is no support for
35       partial compilation.  To achieve the benefits of  partial  compilation,
36       you should compile programs into their own assemblies, and later refer‐
37       ence them with the "-r" flag.
38
39       The Turbo C# compiler generates images (.exe files)  that  contain  CIL
40       byte  code  that can be executed by any system that implements a Common
41       Language Infrastructure virtual machine such as the Microsoft .NET run‐
42       time  engine  on  Windows  or  the Mono runtime engine on Unix systems.
43       Executables are not bound to a specific CPU or operating system.
44
45       The Turbo C# compiler by  default  only  references  three  assemblies:
46       mscorlib.dll, System.dll and System.Xml.dll.   If you want to reference
47       extra libraries you must manually specify them using the -pkg:  command
48       line  option or the -r: command line option.  Alternatively if you want
49       to get all of the System libraries, you can use the -pkg:dotnet command
50       line option.
51

OPTIONS

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

PACKAGES AND LIBRARIES

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

SPECIAL DEFINES

433       The TRACE and DEBUG defines have a special meaning to the compiler.
434
435       By  default  calls  to  methods  and  properties in the System.Diagnos‐
436       tics.Trace class are not generated unless the TRACE symbol  is  defined
437       (either through a "#define TRACE") in your source code, or by using the
438       --define TRACE in the command line.
439
440       By default calls to  methods  and  properties  in  the  System.Diagnos‐
441       tics.Debug  class  are not generated unless the DEBUG symbol is defined
442       (either through a "#define DEBUG") in your source code, or by using the
443       --define DEBUG in the command line.
444
445       Note  that  the effect of defining TRACE and DEBUG is a global setting,
446       even if they are only defined in a single file.
447

DEBUGGING SUPPORT

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

ENVIRONMENT VARIABLES

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

NOTES

476       During compilation the MCS compiler defines the __MonoCS__ symbol, this
477       can  be  used by pre-processor instructions to compile Mono C# compiler
478       specific code.   Please note that this symbol is only to test  for  the
479       compiler,  and  is  not useful to distinguish compilation or deployment
480       platforms.
481

AUTHORS

483       The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap,  Mar‐
484       tin  Baulig, Marek Safar and Raja Harinath.  The development was funded
485       by Ximian, Novell and Marek Safar.
486

LICENSE

488       The Mono Compiler Suite is released under the terms of the GNU  GPL  or
489       the  MIT X11.  Please read the accompanying `COPYING' file for details.
490       Alternative licensing for the compiler is available from Xamarin.
491

SEE ALSO

493       csharp(1), mono(1), pkg-config(1), sn(1)
494

BUGS

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

MAILING LIST

500       The Mono Mailing lists are listed at http://www.mono-project.com/commu
501       nity/help/mailing-lists/
502

MORE INFORMATION

504       The Mono C# compiler was  developed  by  Novell,  Inc  (http://www.nov
505       ell.com)  and Xamarin Inc (http://www.xamarin.com) is based on the ECMA
506       C#         language          standard          available          here:
507       http://www.ecma.ch/ecma1/STAND/ecma-334.htm
508
509       The  home  page  for  the  Mono  C#  compiler  is  at  http://www.mono-
510       project.com/docs/about-mono/languages/csharp/
511
512
513
514                                6 January 2001                          mcs(1)
Impressum