mcs(1)
๐ mcs โ Turbo C# Compiler ๐
okay so you're looking at mcs(1), from the General Commands Manual section of the manual pages ๐ โ this is the Turbo C# Compiler, and bestie, she's a whole icon. let's get into it ๐
โจ NAME โจ
mcs โ the Turbo C# Compiler ๐ฆ
โจ SYNOPSIS โจ
mcs [option] [source-files]
โจ DESCRIPTION โจ
so mcs is the Turbo C# compiler (she also goes by the Mono C# compiler, iykyk), and she's a full implementation of the ECMA-334 language specification ๐. you pass her one or more options to drive the compiler, plus a set of source files. and lowkey you can even drop extra options or arguments into a response file โ you reference a response file by putting the @ symbol in front of its name ๐ธ
the mcs compiler is used to compile against the latest Mono Base Class Library version and fully implements the C# 1.0, 2.0, 3.0, 4.0, 5.0 and 6.0 specifications, with partial support for C# 7.0 ๐ซถ
peep the section on packages for more info, bestie ๐ฆ
the Turbo C# compiler accepts the same command line options that the Microsoft C# compiler does โจ. those options can start with a slash or a dash (/checked is the same as -checked). and additionally, some GNU-like options are supported โ those begin with --. โญ all MCS-specific flags that are not available in the Microsoft C# compiler are available only with the GNU-style options.
C# source files must end with a .cs extension ๐. compiling C# source code requires all the files that make up a library, module or executable to be provided on the command line โ there is no support for partial compilation, periodt. if you want the benefits of partial compilation, you compile programs into their own assemblies, and later reference them with the -r flag ๐
the Turbo C# compiler generates images (.exe files) that contain CIL byte code which can be executed by any system that implements a Common Language Infrastructure virtual machine โ like the Microsoft .NET runtime engine on Windows, or the Mono runtime engine on Unix systems ๐ง. executables are not bound to a specific CPU or operating system, no cap ๐
by default the Turbo C# compiler only references three assemblies: mscorlib.dll, System.dll and System.Xml.dll ๐ธ. if you want extra libraries you must manually specify them using the -pkg: command line option or the -r: command line option ๐. alternatively, if you want to get all of the System libraries, you can use the -pkg:dotnet command line option. slay.
โจ OPTIONS โจ
this is the part where the menu is long and every single item is valid, so let's go ๐
--aboutโ shows you info about the Turbo C# compiler ๐--addmodule:MODULE1[,MODULE2]โ includes the specified modules in the resulting assembly. (modules get created by calling the compiler with the-target:moduleoption โจ)-checked,-checked+โ sets the default compilation mode tochecked. this makes all the math operations checked (the default is unchecked, fyi).-checked-โ sets the default compilation mode tounchecked. this makes all the math operations unchecked โ and this is the default ๐-clscheck-,-clscheck+โ disables or enables the Common Language Specification (CLS) checks. it's enabled by default ๐ฆ
the Common Language Specification (CLS) defines an interoperable subset of types, plus conventions that compilers (CLS producers) and developers must follow to expose code to other programming languages (CLS consumers). so basically it's the friendship pact between languages ๐ค
-codepage:IDโ specifies the code page used to process the input files from the point it is specified on. by default, files get processed in the environment-dependent native code page. the compiler will also automatically detect Unicode files that have an embedded byte mark at the beginning ๐
other popular encodings are 28591 (Latin1), 1252 (iso-8859-1) and 65001 (UTF-8).
MCS supports a couple of shorthands: "utf8" can be used to specify utf-8 instead of using the cryptic 65001, and "reset" restores the automatic handling of code pages. these shorthands are not available on the Microsoft compiler ๐
-define:SYMLIST,-d:SYMLISTโ defines the symbol listed by the semi-colon separated listSYMLISTSYMBOL. you can test this in the source code with the pre-processor, or it can be used by methods that have been tagged with theConditionalattribute ๐ธ-debug,-debug+โ generate debugging information. to obtain stack traces with debugging information, you need to invoke the mono runtime with the--debugflag. the debugging information is stored in a MDB file located in the same output folder as the produced assembly ๐-debug-โ do not generate debugging information. simple as that ๐-delaysign+โ only embed the strongname public key into the assembly. the actual signing must be done in a later stage using the SN tool. this is useful to protect the private key during development ๐. note that delay signing can only be done using a strongname key file (not a key container). the option is equivalent to including[assembly: AssemblyDelaySign (true)]in your source code. compiler option takes precedence over the attributes, periodt.-delaysign-โ the default. strongname (sign) the assembly using the strong name key file (or container). the option is equivalent to including[assembly: AssemblyDelaySign (false)]in your source code. compiler option takes precedence over the attributes โจ-doc:FILEโ extracts the C#/XML documentation from the source code and stores it in the givenFILE๐-errorreportโ this flag is ignored by Mono's C# compiler and is present only to allow MCS to be used as a CSC replacement formsbuild/xbuild๐--fatalโ this one is used for debugging the compiler. it makes the error emission generate an exception that can be caught by a debugger ๐-filealignโ this flag is ignored by Mono's C# compiler and is present only to allow MCS to be used as a CSC replacement formsbuild/xbuild(same vibe as-errorreport, bestie) ๐-fullpathsโ any source code error or warning issued by the compiler includes the file name only by default. this option causes the compiler to issue the absolute file path instead ๐บ๏ธ-keyfile:KEYFILEโ strongname (sign) the output assembly using the key pair present in the specified strong name key file (snk). a full key pair is required by default (or when usingdelaysign-). a file containing only the public key can be used withdelaysign+. the option is equivalent to including[assembly: AssemblyKeyFile ("KEYFILE")]in your source code. compiler option takes precedence over the attributes ๐-keycontainer:CONTAINERโ strongname (sign) the output assembly using the key pair present in the specified container. note thatdelaysign+is ignored when using key containers ๐. the option is equivalent to including[assembly: AssemblyKeyName ("CONTAINER")]in your source code. compiler option takes precedence over the attributes.-langversion:TEXTโ this option specifies the version of the language to use. the feature set is different in each C# version, and this switch can force the compiler to allow only a subset of the features ๐. the possible values are:- Default โ instructs the compiler to use the latest version. equivalent to omitting the switch (this currently defaults to the C# 6.0 language specification).
- ISO-1 โ restrict the compiler to use only first ISO standardized features. using features like generics, static classes, or anonymous methods will lead to error ๐
- ISO-2 โ restrict the compiler to use only the second ISO standardized features. this allows the use of generics, static classes, iterators and anonymous methods, for example.
- 3 โ restrict the compiler to use only the features available in C# 3.0 (a superset of ISO-1 and ISO-2).
- 4 โ restrict the compiler to use only the features available in the C# 4.0 specification.
- 5 โ restrict the compiler to use only the features available in the C# 5.0 specification.
- 6 โ restrict the compiler to use only the features available in the C# 6.0 specification.
- experimental โ enables unstable features from upcoming versions of the language ๐ฅ
notice that this flag only restricts the language features available to the programmer. the version of the produced assemblies can be controlled using the SDK option ๐
-lib:PATHLISTโ each path specified in the comma-separated list directs the compiler to look for libraries in that specified path ๐-L PATHโ directs the compiler to look for libraries in the specified path. you can provide multiple paths by using the option multiple times โจ-main:CLASSโ tells the compiler whichCLASScontains the entry point. super useful when you're compiling several classes that each have aMainmethod ๐ช-nostdlib,-nostdlib+โ use this flag if you want to compile the core library. it makes the compiler load its internal types from the assembly being compiled ๐ง-noconfig,-noconfig+โ disables the default compiler configuration from being loaded. the compiler by default has references to the system assemblies ๐ธ-nowarn:WARNLISTโ makes the compiler ignore warnings specified in the comma-separated listWARNLIST๐คซ-optimize,-optimize+,-optimize-โ controls compiler code generation optimizations on the code. using-optimizeor-optimize+turns optimizations on,-optimize-turns them off. the default inmcsisoptimize-. the option can be mixed with-debug, but for the best debugging experience it's recommended to leave the options off ๐ซถ-out:FNAME,-o FNAMEโ names the output file to be generated ๐--parseโ used for benchmarking. the compiler will only parse its input files โฑ๏ธ-pathmap:K=V[,Kn=Vn]โ sets a mapping for source path names used in generated output ๐บ๏ธ-pkg:package1[,packageN]โ reference assemblies for the given packages ๐ฆ
the compiler will invoke pkg-config --libs on the set of packages specified on the command line to obtain libraries and directories to compile the code.
this is typically used with third party components, like this:
$ mcs -pkg:gtk-sharp demo.cs
...to be continued, bestie โ part 2 is coming ๐ฆ
-pkg:dotnetโ tells the compiler to reference theSystem.*libraries that a normal dotnet framework install has lying around. Heads up though: this does NOT include all the Mono libraries, only theSystem.*ones. It's a lil convenience shortcut for the porting girlies. ๐ซถ-platform:ARCHโ sets your target platform, bestie. The values you can pass are:anycpu,anycpu32bitpreferred,arm,x86,x64oritanium. And the default?anycpu. iconic default behavior tbh.-resource:RESOURCE[,ID]โ embeds the resource file you point it at. The optionalIDlets you give that resource a different name. Skip theIDand the resource name is just the file name. simple as. โจ-linkresource:RESOURCE[,ID]โ links to theRESOURCEyou specify. The optionalIDlets you name the linked resource. linky linky.-r:ASSEMBLY1[,ASSEMBLY2],-reference ASSEMBLY1[,ASSEMBLY2]โ references the named assemblies so you can use classes from them in your program. The assembly gets loaded from either the system directory where all the assemblies live, or from the path you explicitly gave with the-Loption.
You can also split assemblies with a semicolon instead of a comma. options options options ๐
-reference:ALIAS=ASSEMBLYโ extern alias reference support for C#. ๐
So like, if you've got different assemblies that hand you the same types, extern alias support lets you give them names so your software can tell them apart. The types from ASSEMBLY get exposed as ALIAS, and then in your C# source you gotta do:
extern alias ALIAS;
to bring it into your namespace. Example time: to deal with two graphics libraries that both define "Graphics.Point", one in "OpenGL.dll" and one in "Postscript.dll", you'd invoke the compiler like this:
mcs -r:Postscript=Postscript.dll -r:OpenGL=OpenGL.dll
And in your source code, you'd write:
extern alias Postscript;
extern alias OpenGL;
class X {
// This is a Graphics.Point from Postscrip.dll
Postscript.Point p = new Postscript.Point ();
// This is a Graphics.Point from OpenGL.dll
OpenGL.Point p = new OpenGL.Point ();
}
tell me that's not the cleanest thing you've ever seen ๐ญ
-recurse:PATTERN,--recurse PATTERNโ does recursive compilation using the pattern you give it. In Unix the shell does the globbing for you, so you might wanna use it like this:
$ mcs -recurse:'*.cs'
๐ฆ
-sdk:VERSIONโ specifies which version of Base Class Library assemblies to use for compilation. These predefined values are valid:2,4(default), plus any custom value. The predefined version number means... when a custom value is specified,mcswill try to find the Base Class Libraries in the mono installed locationPREFIX/lib/mono/<value>. paths, my beloved.--shellโ starts the compiler up in interactive mode, giving you a C# shell for statements and expressions. Shortcut? Just use thecsharpcommand directly. ๐ฅ--stacktraceโ generates a stack trace at the time the error is reported. Super useful for debugging the compiler itself. dev girlies rise.-target:KIND,-t:KINDโ specifies your desired target. Possible values:exe(plain executable),winexe(Windows.Forms executable),library(component libraries) andmodule(partial library). pick your fighter ๐--timestampโ another debugging flag. Displays the times at various points in the compilation process. โฐ-unsafe,-unsafe+โ enables compilation of unsafe code. living dangerously, i see. ๐-vโ debugging! Turns on verbose yacc parsing.--versionโ shows the compiler version. โญ-warnaserror,-warnaserror+โ every single compiler warning gets reported as an error. no warnings allowed, periodt.-warnaserror:W1,[Wn],-warnaserror+:W1,[Wn]โ treats one or more compiler warnings as errors. just the ones you pick.-warnaserror-:W1,[Wn]โ sets one or more compiler warnings to be always treated as warnings. This becomes useful when you use it together with-warnaserror. the exception to the rule, love that for you.-warn:LEVELโ sets the warning level.0is the lowest,4is the highest. Default is4. ๐-win32res:FILEโ specifies a Win32 resource file (.res) to be bundled into the resulting assembly. ๐-win32icon:FILEโ attaches the icon inFILEon the output into the resulting assembly. cute lil icon moment.--โ use this to stop option parsing, so option-looking parameters can be passed on the command line. the escape hatch, bestie.
๐ฆ PACKAGES AND LIBRARIES ๐ฆ
When you're referencing an assembly, if the assembly name is a path, the compiler tries to load the assembly at that path. If it doesn't, then the compiler tries loading the assembly from the current directory, the compiler base directory, and if it's not found in any of those places, in the directories specified as arguments to the -lib: command argument.
The compiler uses the library path to locate libraries, and it can reference libraries from a particular package if that directory is used. To make packages easier to use, the C# compiler includes the -pkg: command line option, which loads specific collections of libraries.
Libraries visible to the compiler are stored relative to the installation prefix under PREFIX/lib/mono/, which is called the PACKAGEBASE. And the defaults for mcs, gmcs and smcs are:
mcsโ references thePACKAGEBASE/1.0directorygmcsโ references thePACKAGEBASE/2.0directorysmcsโ references thePACKAGEBASE/2.1directory
Those are the only runtime profiles that exist. Even though other directories exist (like 3.0 and 3.5), those aren't really runtime profiles โ they're just placeholders for extra libraries that build on the 2.0 foundation. the more you know ๐ซ
Software providers distribute software that's installed relative to the PACKAGEBASE directory. This is integrated into the gacutil tool, which not only installs public assemblies into the Global Assembly Cache (GAC) but also installs them into the PACKAGEBASE/PKG directory (where PKG is the name passed to the -package flag of gacutil).
As a developer, if you wanna consume the Gtk# libraries, you'd invoke the compiler like this:
$ mcs -pkg:gtk-sharp-2.0 main.cs
The -pkg: option tells the compiler to fetch the definitions for gtk-sharp-2.0 from pkg-config, which is equivalent to passing the C# compiler the output of:
$ pkg-config --libs gtk-sharp-2.0
Usually this just references the libraries from PACKAGEBASE/PKG. ๐ซถ
Even though there are directory names for 3.0 and 3.5, that does not mean there are 3.0 and 3.5 compiler editions or profiles. Those are merely new libraries that have to be manually referenced, either with the proper -pkg: invocation, or by referencing the libraries directly.
๐ฎ SPECIAL DEFINES ๐ฎ
The TRACE and DEBUG defines have a special meaning to the compiler. iykyk.
By default, calls to methods and properties in the System.Diagnostics.Trace class are not generated unless the TRACE symbol is defined (either through a "#define TRACE" in your source code, or by using --define TRACE on the command line).
By default, calls to methods and properties in the System.Diagnostics.Debug class are not generated unless the DEBUG symbol is defined (either through a "#define DEBUG" in your source code, or by using --define DEBUG on the command line).
Bestie, real talk: the effect of definingTRACEandDEBUGis a global setting, even if they're only defined in a single file. ๐
๐ DEBUGGING SUPPORT ๐
When you use the "-debug" flag, MCS generates a file with the .mdb extension that contains the debugging information for the generated assembly. That file gets consumed by the Mono debugger (mdb). debugging era fr.
๐ ENVIRONMENT VARIABLES ๐
MCS_COLORSโ if this variable is set, it contains a string in the form"foreground,background"that says which color to use to display errors on some terminals. ๐จ
The background is optional and defaults to your terminal's current background.
The possible colors for foreground are: black, red, brightred, green, brightgreen, yellow, brightyellow, blue, brightblue, magenta, brightmagenta, cyan, brightcyan, grey, white and brightwhite.
The possible colors for background are: black, red, green, yellow, blue, magenta, cyan, grey and white.
For example, you could set these variables from your shell:
export MCS_COLORS
MCS_COLORS=errors=brightwhite,red
And you can disable the built-in color scheme by setting this variable to "disable". no more pretty colors ๐ญ
๐ NOTES ๐
During compilation the MCS compiler defines the __MonoCS__ symbol. You can use it in pre-processor instructions to compile Mono C# compiler specific code.
Ok but listen: this symbol is only to test for the compiler, and it is not useful for distinguishing compilation or deployment platforms. don't get it twisted bestie ๐
๐ AUTHORS ๐
The Mono C# Compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar and Raja Harinath. The development was funded by Ximian, Novell and Marek Safar. legends, all of them ๐
๐ LICENSE ๐
The Mono Compiler Suite is released under the terms of the GNU GPL or the MIT X11. Please read the accompanying COPYING file for details. Alternative licensing for the compiler is available from Xamarin. read the fine print, bestie ๐
๐ฆ SEE ALSO ๐ฆ
csharp(1), mono(1), pkg-config(1), sn(1)
๐ BUGS ๐
To report bugs in the compiler, you must file them on our bug tracking system, at: http://www.mono-project.com/community/bugs/
do it. the devs are begging you. ๐
๐ฌ MAILING LIST ๐ฌ
The Mono Mailing lists are listed at http://www.mono-project.com/community/help/mailing-lists/
โญ MORE INFORMATION โญ
The Mono C# compiler was developed by Novell, Inc (http://www.novell.com) and Xamarin Inc (http://www.xamarin.com) is based on the ECMA C# language standard available here: http://www.ecma.ch/ecma1/STAND/ecma-334.htm
The home page for the Mono C# compiler is at http://www.mono-project.com/docs/about-mono/languages/csharp/
and that's the whole page bestie ๐ซถ this lil manual is dated 6 January 2001 and it's mcs(1). go forth and compile slayfully ๐โจ
๐ฆ where this page comes from
- debian bookworm: mono-mcs 6.8.0.105+dfsg-3.3+deb12u1 ยท MIT
- debian trixie: mono-mcs 6.12.0.199+dfsg-6 ยท MIT
- ubuntu jammy: mono-mcs 6.8.0.105+dfsg-3.2 ยท MIT
- ubuntu noble: mono-mcs 6.8.0.105+dfsg-3.6ubuntu2 ยท MIT
- ubuntu questing: mono-mcs 6.12.0.199+dfsg-6
- ubuntu resolute: mono-devel 6.14.1+ds2-2 ยท MIT
- ubuntu stonking: mono-devel 6.14.1+ds2-3 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms