linuxmono

Compile Using MONO - C# with Reference To A C# Library?


I have a C# library (DLL)

//  ProgramLib.cs //
using System;

namespace ProgramLibrary
{
    public class Lib
    {
        public Lib()
        {
            Console.WriteLine("Lib Created");
        }
    }
}

And I have the following console program

//  Program.cs //
using System;
using ProgramLibrary;

class MainClass
{
    public static void Main (string[] args)
    {
        ProgramLibrary.Lib lib = new ProgramLibrary.Lib();
    }
}

In a linux environment, if both files reside in the same directory

What is the Mono compiler (mcs) command that compiles Program.cs with reference to ProgramLib.cs?


Solution

  • First compile ProgramLib to ProgramLib.dll, then reference it:

    $ gmcs -t:library ProgramLib.cs
    $ gmcs -r:ProgramLib.dll Program.cs