Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Thanks all!!

like image 571
divinci Avatar asked Sep 30 '09 07:09

divinci


People also ask

Is Mono a compiler?

The Mono C# compiler is considered feature complete for C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0 and C# 6.0 (ECMA) and it has partial support for C# 7. Historically, various version of same compiler existed.

What is the compiler for C#?

Visual Studio - Windows only Visual Studio is the compiler and IDE created by Microsoft for Windows computers. Visual Studio has several versions. The professional version can compile C# code, as well as a number of other languages.


1 Answers

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

$ gmcs -t:library ProgramLib.cs
$ gmcs -r:ProgramLib.dll Program.cs
like image 100
Jon Skeet Avatar answered Sep 20 '22 18:09

Jon Skeet