Redirected from page "Mono-Wine bridge"
(Clear message)

  Mono

Mono

Mono is an open-source and cross-platform implementation of the .NET Framework. When the Windows version of Mono is installed in Wine, it can be used to run .NET applications. The current release of Mono is 2.6.4. It can be obtained from Mono's website or by using the mono26 verb in winetricks.

As of version 1.1.43, Wine uses Mono's embedding API to load .NET exe files if the Windows version of Mono is installed in Wine.

In most cases, MS .NET works better than Mono in Wine.

What Wine needs from the Community

Fixing Mono Class Library and Runtime bugs on Windows will help Wine as well.

Implement the System.Windows.Forms.AxHost class. I (Vincent Povirk) suspect that writing a simple ActiveX container program that uses that class, and writing the class itself, will also expose other bugs in Mono's COM interop code.

Mono keeps a list of technologies that they wouldn't mind being a part of the project, but don't want to write themselves: http://www.mono-project.com/Mono_Project_Roadmap#Unsupported_technologies

Largest among these is the Windows Presentation Foundation (WPF) API that is a part of .NET 3.0. It would be fantastic if someone could volunteer to implement these technologies in Mono so that applications using them can run in Wine

A run-test-onwine build target similar to the existing run-test-ondotnet target would be very handy, naively assuming Wine is capable of running .NET executables.

Debugging

As of version 1.1.42 and Mono 2.6, the WINE_MONO_TRACE environment variable may be set as follows to trace calls within Mono:

    all                  All assemblies
    none                 No assemblies
    program              Entry point assembly
    assembly             Specifies an assembly
    M:Type:Method        Specifies a method
    N:Namespace          Specifies a namespace
    T:Type               Specifies a type
    EXPR                 Includes expression
    -EXPR                Excludes expression
    EXPR,EXPR            Multiple expressions
    disabled             Don't print any output until toggled via SIGUSR2

This option is the same as the --trace option in mono, and you can see it by running "mono --help-trace".

Note that "All assemblies" includes the program itself and all libraries shipped with it. Mono is capable of tracing any .NET code. You probably should avoid the "all" trace if there might be proprietary code running in the process.

Activating any trace at all, even a bogus assembly name, will cause Mono to print out all exceptions as they occur. This can be useful, but it can also be misleading as some exceptions are perfectly normal.

In earlier versions of Wine, the "MONO_TRACE" environment variable may work.

If you see "Stacktrace:" in the console, this means that Mono has crashed. To debug, set MONO_DEBUG=suspend-on-sigsegv. You will then see "Received SIGSEGV, suspending..." after the crash, and you can attach winedbg to the process.

Documentation

Standard .NET namespaces and classes are documented at MSDN here: http://msdn.microsoft.com/en-us/library/aa388745%28VS.85%29.aspx

Known Issues

  • Installers for .NET programs will often insist on installing the Microsoft version of .NET. Wine should be fixed so that it appears to these installers that .NET is already installed.
  • Mono's Embedding API has changed between 2.6 and trunk. Wine is not yet compatible with the new API that will be used in Mono 2.8. We will have to wait for the API to stabilize before adding support to Wine.
  • Most of mscoree.dll is a stub.
  • Libraries installed to the Global Assembly Cache are not accessible from Mono when it is invoked by Wine.
  • Mono's Windows Forms implementation makes heavy use of GdiPlus, and Wine's builtin gdiplus.dll is not very good.

  • Mono does not implement Windows Presentation Foundation.

  • .NET programs are subject to general bugs in Wine or in Mono.
  • There's no "proper" way to run the Mono tests on Wine.
  • There's no "proper" way to use a custom build of Mono in Wine.

Cross-Compiling for Wine

See also http://www.mono-project.com/Compiling_Mono, especially http://www.mono-project.com/Cross-compiling_Mono_for_Windows

You will need the mono source code for this. You should use mono/ and mcs/ from mono svn trunk if you can, because that is easiest.

To get the needed dependencies, use:

#!/bin/sh
# Copyright 2010 Austin English
# LGPL 2.1
# Sets up dependencies needed to cross compile mono.
# See http://www.mono-project.com/Cross-compiling_Mono_for_Windows
# and http://wiki.winehq.org/Mono
# You'll need to run it as root/sudo, since you likely don't have write access to /usr
# If you're not on Ubuntu, you may need to change the MONOCROSS variable below.
set -ex
if [ ! -w /usr/ ]
then
    echo "You must run $0 as root/sudo"
    exit 1
fi

MONOCACHE="$HOME/.monocache"
MONOCROSS="/usr/i586-mingw32msvc"
olddir="`pwd`"
download() {
    file=`basename "$1"`
    mkdir -p "$MONOCACHE"
    if [ ! -f "$MONOCACHE/$file" ]
    then
        cd "$MONOCACHE"
        wget -O "$file" "$1"
        cd "$olddir"
    fi
}
download http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/libjpeg-6b-bin.zip
download http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/libjpeg-6b-lib.zip
download http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/giflib-4.1.4-bin.zip
download http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/giflib-4.1.4-lib.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/expat-2.0.0.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/fontconfig_2.8.0-2_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/fontconfig-dev_2.8.0-2_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/freetype_2.3.11-2_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/freetype-dev_2.3.11-2_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime-0.17-1.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime-dev-0.17-1.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/libpng_1.2.40-1_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/libpng-dev_1.2.40-1_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/libtiff-dev-3.8.2.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/proxy-libintl-20080612.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.16/glib-2.16.5.zip
download http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.16/glib-dev-2.16.5.zip
# Setup the dependencies
cd $MONOCROSS
for pkg in $MONOCACHE/*.zip
do
    unzip -o $pkg
done

Mono should build from trunk extremely easily. Start by using the above script to install the needed dependencies, then do:

$ mkdir monosvn
$ cd monosvn
$ svn co svn://anonsvn.mono-project.com/source/trunk/mcs
$ svn co svn://anonsvn.mono-project.com/source/trunk/mono
$ cd mono
# adjust the mingw values if they are different on your distribution
$ ./build-mingw32.sh -d /usr/i586-mingw32msvc -m i586-mingw32msvc

Warning: If you have $CC set in your environment, unset it, since it will conflict.

This produces a .zip file containing a build of mono and its dependencies.

Building Mono 2.6

if you are building Mono from the 2.6 branch, you may need to account for the following problems. The 2.6.3 tarball will not cross-compile at all.

The dependencies include .pc files that have prefixes beginning with c:. To make the Linux pkg-config work with cross-compiling, I had to configure with PKG_CONFIG='/usr/bin/pkg-config --define-variable=prefix=/usr/i586-mingw32msvc' (which meant modifying build-mingw32.sh).

I also configure with CFLAGS=-gstabs, which gets me debugging symbols in libmono.dll.

Cross-compiling does not work currently due to some mono bugs. From the mono-2-6 branch, I needed the patches in comments 1, 2, and 3 of https://bugzilla.novell.com/show_bug.cgi?id=531767.

The command-line arguments to build-mingw.sh have changed, so the build command above will not work.

My build command line on Ubuntu 9.10 looked like this:

$ ./build-mingw32.sh /usr i586-mingw32msvc

Using Custom Mono Builds in Wine

Currently, only versions of Mono <= 2.6 will work in Wine. Builds from trunk will run, but Wine will not be able to use them to run .NET executables.

To use a custom build of Mono in Wine, you must set the following registry values:

HKEY_LOCAL_MACHINE\Software\Novell\Mono\DefaultCLR = "custom"
HKEY_LOCAL_MACHINE\Software\Novell\Mono\custom\SdkInstallRoot = "z:\path\to\mono\root"

The "root" directory contains bin, lib, and etc directories.

Test Suite

See http://www.mono-project.com/Testing first.

Running the Mono test suite on Wine is very important for fixing bugs (in Mono and in Wine), and I suspect that MS .NET hosted in Wine will also benefit from some of the fixes made for the Mono tests.

You would normally run 'make run-test' to run the tests. You can force the test suite to run with a different mono binary by setting the RUNTIME variable. To do this properly with a cross-built mono.exe, I had to write a wrapper script:

   1 #!/usr/bin/env python
   2 import os
   3 import sys
   4 import subprocess
   5 unix_mono_prefix = os.environ['MONO_WINE_DIR']
   6 def unix_to_windows_path(path):
   7     popen = subprocess.Popen(['wine', 'winepath', '--windows', path], stdout=subprocess.PIPE)
   8     stdout, stderr = popen.communicate()
   9     popen.wait()
  10     return stdout.rstrip('\n')
  11 windows_mono_prefix = unix_to_windows_path(unix_mono_prefix)
  12 #work-around for http://bugs.winehq.org/show_bug.cgi?id=22168
  13 if 'GNOME_DESKTOP_SESSION_ID' in os.environ: del os.environ['GNOME_DESKTOP_SESSION_ID']
  14 if 'DESKTOP_SESSION' in os.environ: del os.environ['DESKTOP_SESSION']
  15 os.environ['MONO_PREFIX'] = windows_mono_prefix
  16 mono_paths = []
  17 for path in os.environ.get('MONO_PATH', '').split(':'):
  18     mono_paths.append(unix_to_windows_path(path))
  19 os.environ['MONO_PATH'] = ';'.join(mono_paths)
  20 popen = subprocess.Popen(['wine', windows_mono_prefix+'\\bin\\mono.exe'] + sys.argv[1:])
  21 sys.exit(popen.wait())

To invoke the tests with this wrapper, I ran them this way:

$ MONO_WINE_DIR=path/to/mono/mono-win32/mono-2.6.3-branches-2-6-r154484/ make -k RUNTIME=path/to/wine-mono-wrapper run-test &>test-summary.txt

The tests hang at the end when invoked this way for some reason.

Mono (last edited 2010-07-12 14:23:16 by VincentPovirk)