Monoをsvn trunkのソースからビルドしてインストールする手順。 ビルドに使用した環境はUbuntu 10.04 Desktop。 本文は2010年05月02日時点のバージョンに基づく。
なお、現在はGitHubに移行しているため、svn://anonsvn.mono-project.com/からはチェックアウト出来なくなっている。 GitHubのソースからビルド・インストールする手順はMono のビルド・インストール (Git master)。
ここで紹介する手順はMono本体といくつかのアセンブリをインストールするためのもの。 ディストリビューションが提供しているバージョンのMonoと共存できるようにするため、/opt/mono/trunkにインストールする。
1つの環境に複数のMonoをインストールする方法についてはParallel Mono Environments - Monoで詳しく解説されている。
ビルドにはgcc、libtool、autotools、gettext、pkg-config等が必要になるので、あらかじめインストールしておく必要がある。
libgdiplus
依存するパッケージのインストール
sudo apt-get install \
libcairo2-dev libexif-dev libfreetype6-dev libfontconfig1-dev libgif-dev libglib2.0-dev libjpeg62-dev \
libpng12-dev libtiff4-dev libungif4-dev libx11-dev libxrender-dev
ソースのチェックアウトとautogen、configure
svn co svn://anonsvn.mono-project.com/source/trunk/libgdiplus
cd ./libgdiplus
./autogen.sh --prefix=/opt/mono/trunk
configureの結果例。
--- Configuration summary * Installation prefix = /opt/mono/trunk * Cairo = 1.8.10 (system) * Text = cairo * EXIF tags = yes * Codecs supported: - TIFF: yes - JPEG: yes - GIF: yes - PNG: yes NOTE: if any of the above say 'no' you may install the corresponding development packages for them, rerun autogen.sh to include them in the build. --- Now type `make' to compile
ビルド、インストール
configureした結果に問題が無ければmake、make installする。
make
sudo make install
正しくインストールできたか確認する。
ls -l /opt/mono/trunk/lib/libgdiplus*
Mono本体(コンパイラ、クラスライブラリ)
依存するパッケージのインストール
sudo apt-get install \
bison
ソースのチェックアウトとautogen、configure
.NET Framework 4のアセンブリを含めない場合は、--with-profile4=noを指定する。
svn co svn://anonsvn.mono-project.com/source/trunk/mono svn://anonsvn.mono-project.com/source/trunk/mcs
cd mono
./autogen.sh --prefix=/opt/mono/trunk --with-libgdiplus=installed --with-ikvm-native=no --with-moonlight=yes --with-monotouch=no --with-mcs-docs=no --with-x
configureの結果例。
mcs source: ../mcs olive source: Engine: GC: included GLIB: embedded TLS: __thread SIGALTSTACK: yes Engine: Building and using the JIT oprofile: no BigArrays: no DTrace: no Parallel Mark: yes LLVM Back End: no Libraries: Moon Profile: yes MonoTouch: no JNI support: libgdiplus: assumed to be installed zlib: system zlib Now type `make' to compile
ビルド、インストール
コンパイルする環境にMonoおよびmcsがない場合は、makeする前に最新のMonoLite(Mono Daily Packages)を取得しておく。
make get-monolite-latest
なお、このコマンドでから取得したバイナリでビルドできない場合は、以下の5つのバイナリを別の環境からコピーするなどして../mcs/class/lib/monolite/に配置すればビルドできるようになる。
- mscorlib.dll
- System.dll
- System.Xml.dll
- Mono.Security.dll
- mcs.exe
準備が整ったら、make、make installする。
make
sudo make install
動作確認
新しくMonoをインストールした場合
mono -Vでmonoが動作することを確認する。
$ mono -V Mono JIT compiler version 2.7 (/trunk/mono r156582 2010年 5月 2日 日曜日 17:48:25 JST) Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com TLS: __thread GC: Included Boehm (with typed GC and Parallel Mark) SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none Misc: debugger softdebug LLVM supported
既に別のバージョンのMonoが存在する環境にインストールした場合
新しく/opt/monoにインストールしたMonoを参照できるように、環境変数を設定するスクリプトを用意しておく。 参考: Parallel Mono Environments - Mono
#!/bin/bash
MONO_PREFIX=/opt/mono/trunk
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig
PATH=$MONO_PREFIX/bin:$PATH
まずmono -Vで既にインストールされているmonoが動作することを確認する。
$ which mono /usr/bin/mono $ mono -V Mono JIT compiler version 2.4.4 (Debian 2.4.4~svn151842-1ubuntu4) Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com TLS: __thread GC: Included Boehm (with typed GC) SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none
続いて、先ほど用意したスクリプトを読み込んだあとでmono -Vを実行し、新しくインストールしたmonoが動作することを確認する。
$ source mono-trunk-env $ which mono /opt/mono/trunk/bin/mono $ mono -V Mono JIT compiler version 2.7 (/trunk/mono r156582 2010年 5月 2日 日曜日 17:48:25 JST) Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com TLS: __thread GC: Included Boehm (with typed GC and Parallel Mark) SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none Misc: debugger softdebug LLVM supported
GAC
gacutil -lでアセンブリがGACに登録されていることを確認する。 GACのパスを明示的に指定する場合は-rootオプションで指定する(例えばgacutil2 -l -root /usr/lib/など)。
$ gacutil2 -l The following assemblies are installed into the GAC: : System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.ComponentModel.Composition, Version=2009.22.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 :
gmcs (2.0ランタイム用C#コンパイラ)
gmcs --aboutでgmcsのバージョンを確認する。
$ gmcs --about The Mono C# compiler is Copyright 2001-2008, Novell, Inc. The compiler source code is released under the terms of the MIT X11 or GNU GPL licenses For more information on Mono, visit the project Web site http://www.mono-project.com The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto
dmcs (4.0ランタイム用C#コンパイラ)
C# 4.0よりサポートされる機能を含むコードがコンパイル出来るかどうか試す。
using System;
class Test {
static void Print(int x = 1, int y = 2, int z = 3)
{
Console.WriteLine("x: {0}", x);
Console.WriteLine("y: {0}", y);
Console.WriteLine("z: {0}", z);
Console.WriteLine();
}
public static void Main()
{
Print(x: 17, z: 23);
Print();
}
}
$ dmcs test.cs && mono test.exe x: 17 y: 2 z: 23 x: 1 y: 2 z: 3
csharp(C#シェル)
csharpシェルが動作するか確認する。
$ csharp Mono C# Shell, type "help;" for help Enter statements below. csharp> Console.WriteLine(Environment.Version); 4.0.30319.1 csharp> Console.WriteLine(Environment.OSVersion); Unix 2.6.32.21 csharp> quit; null
その他のアセンブリ・ライブラリ
gluezilla
依存するパッケージのインストール。
sudo apt-get install \
libgtk2.0-dev libnss3-dev libnspr4-dev xulrunner-dev
ソースのチェックアウトとautogen、configure。
svn co svn://anonsvn.mono-project.com/source/trunk/gluezilla
cd ./gluezilla/
./autogen.sh --prefix=/opt/mono/trunk
configureの結果例。
checking Gtk+ 2.0... found checking Mono... found checking Mozilla NSPR... nspr checking Mozilla NSS... nss checking Mozilla XPCOM > 1.8... libxul-embedding-unstable : Now type `make' to compile
問題が無ければ、make、make installする。
make
sudo make install
gluezillaの動作テスト
gluezillaが動作するかテストしたい場合は、tests/browser/にあるテスト用のアプリケーションをビルド・起動して動作を確認できる。
まず、ldconfigでライブラリのリンク・キャッシュを再構成する。
sudo ldconfig
次に、テスト用のMakefileで指定されているアセンブリ参照の誤りを修正する。
$ cd tests/browser/ $ diff Makefile.org Makefile 348c348 < gmcs -debug -pkg:dotnet -r:Mono.Mozilla.dll -target:exe -out:$@ $(test_build_sources) --- > gmcs -debug -pkg:dotnet -r:Mono.WebBrowser.dll -target:exe -out:$@ $(test_build_sources)
修正後、make testでテスト用のアプリケーションが起動する。 起動するとウィンドウが開くので、アドレスバーに適当なURLを入れてページが表示されるか確認する。
Mono.Addins
gtk-sharp-2.0が必要になるので、別途ビルドするかパッケージをインストールする。
sudo apt-get install gtk-sharp2
ソースのチェックアウトとautogen、configure。
svn co svn://anonsvn.mono-project.com/source/trunk/mono-addins
cd mono-addins/
./autogen.sh --prefix=/opt/mono/trunk
configureの結果例。
Configuration summary * Installation prefix = /opt/mono/trunk * gui support: yes * unit tests: no * documentation: no
問題が無ければ、make、make installする。
make
sudo make install
mono-tools
gtk-sharp-2.0, gnome-sharp(2.0または3.14)が必要になるので、別途ビルドするかパッケージをインストールする。
sudo apt-get install gtk-sharp2 gnome-sharp2
また、オプションで以下のパッケージも参照されるので、必要ならインストールしておく。
- gecko-sharp
- gtkhtml-sharp
- webkit-sharp
ソースのチェックアウトとautogen、configure。
svn co svn://anonsvn.mono-project.com/source/trunk/mono-tools
cd mono-tools/
./autogen.sh --prefix=/opt/mono/trunk/
configureの結果例。
--- Configuration summary * Installation prefix = /opt/mono/trunk * Using Gecko = no * Using GtkHtml = no * Using Mono.WebBrowser = yes * Using WebKit = no * Using Gnome = yes NOTE: if any of the above say 'no' you may install the corresponding development packages for them, rerun autogen.sh to include them in the build.
問題が無ければ、make、make installする。
make
sudo make install
リビジョン156593の時点では、Gendarmeとgsharpがビルドできないようなので、以下の箇所を修正した。
Index: gendarme/framework/Gendarme.Framework.Helpers/MethodSignature.cs
===================================================================
--- gendarme/framework/Gendarme.Framework.Helpers/MethodSignature.cs (リビジョン 156593)
+++ gendarme/framework/Gendarme.Framework.Helpers/MethodSignature.cs (作業コピー)
@@ -49,7 +49,7 @@
/// }
/// </code>
/// </example>
- /// <seealso cref="Gendarme.Framework.Helpers.MethodSignatures"/>
+ // <seealso cref="Gendarme.Framework.Helpers.MethodSignatures"/>
public class MethodSignature {
/// <summary>
Index: gendarme/framework/Gendarme.Framework.Helpers/MethodSignatures.cs
===================================================================
--- gendarme/framework/Gendarme.Framework.Helpers/MethodSignatures.cs (リビジョン 156593)
+++ gendarme/framework/Gendarme.Framework.Helpers/MethodSignatures.cs (作業コピー)
@@ -37,7 +37,7 @@
/// <summary>
/// Defines commonly used MethodSignatures
/// </summary>
- /// <see cref="Gendarme.Framework.Helpers.MethodSignature"/>
+ // <see cref="Gendarme.Framework.Helpers.MethodSignature"/>
public static class MethodSignatures {
private static readonly string [] NoParameter = new string [0];
@@ -50,7 +50,7 @@
// System.Object
public static readonly new MethodSignature Equals = new MethodSignature ("Equals", "System.Boolean", new string [] { "System.Object" },
(method) => (CheckAttributes (method, MethodAttributes.Public)));
- public static readonly MethodSignature Finalize = new MethodSignature ("Finalize", "System.Void", NoParameter,
+ public static readonly new MethodSignature Finalize = new MethodSignature ("Finalize", "System.Void", NoParameter,
(method) => (CheckAttributes (method, MethodAttributes.Family)));
public static readonly new MethodSignature GetHashCode = new MethodSignature ("GetHashCode", "System.Int32", NoParameter,
(method) => (CheckAttributes (method, MethodAttributes.Public | MethodAttributes.Virtual)));
Index: gsharp/Shell.cs
===================================================================
--- gsharp/Shell.cs (リビジョン 156593)
+++ gsharp/Shell.cs (作業コピー)
@@ -72,7 +72,7 @@
Buffer.InsertWithTagsByName (ref end, "Mono C# Shell, type 'help;' for help\n\nEnter statements or expressions below.\n", "Comment");
ShowPrompt (false);
- Evaluator.InteractiveBaseClass = typeof (InteractiveGraphicsBase);
+ //Evaluator.InteractiveBaseClass = typeof (InteractiveGraphicsBase);
Evaluator.Run ("LoadAssembly (\"System.Drawing\");");
Evaluator.Run ("using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Drawing;");
gsharpの方はこの修正で正しく動作するか未検証。
mono-debugger
以下は2010年04月20日現在のバージョンでの手順。
依存するパッケージのインストール。
sudo apt-get install libncurses5-dev
ソースのチェックアウトとautogen、configure。
svn co svn://anonsvn.mono-project.com/source/trunk/debugger mono-debugger
cd mono-debugger
./autogen.sh --prefix=/opt/mono/trunk
configureの結果に問題が無ければ、make、make installする。
make
sudo make install
メモ
Ubuntu 9.10 Server用
Ubuntu 9.10 Serverインストール直後の状態から、JITコンパイラ・C#コンパイラ・ランタイム(.NET 4含まず)のみをビルド・インストールする手順。 2009年11月01日現在のバージョンに基づく。
$ sudo apt-get install build-essential bison autoconf automake1.9 libtool libglib2.0-dev gettext $ svn co svn://anonsvn.mono-project.com/source/trunk/mono svn://anonsvn.mono-project.com/source/trunk/mcs $ cd mono $ ./autogen.sh --prefix=/usr/local --with-libgdiplus=installed --with-large-heap=no --with-ikvm-native=no --with-monotouch=no --with-moonlight=no --with-profile2=yes --with-profile4=no $ make get-monolite-latest $ make $ sudo make install