[Mono-dev] Compiling mono on windows for developing (not running)

Alex J Lennon ajlennon at dynamicdevices.co.uk
Sun May 4 10:31:06 UTC 2014


On 26/04/2014 10:37, Martin Thwaites wrote:
>
> Thanks Edward,
>
> I'll have to wait until someone puts a guide together about developing
> on windows as I am seriously out of my depth.  I've spent about 2
> evenings so far trying to get mono to build in cygwin, but coming up
> with various errors that googling isn't solving.
>

Hi Martin,

I've been trying to do the same thing for the  past few days as I can't
find a binary release of Mono 3.4.0 for Windows and I want to build
locally with 3.4.0 to remote debug on my ARM targets which are also
running 3.4.0.

There seem to be a variety of tutorials out there which are all helpful
but none has quite worked for me.

I am working on some documentation at present, which I'm going to upload
to a wiki somewhere or other when I have it finished and polished up.

I've just seen your email though, so these work-in-progress notes may be
of help to you now.

If they are of help I'd appreciate your feedback with what worked, any
corrections/clarifications/additions so I can improve this.

Thanks, Best Regards,

Alex

------------------------------------------------------------------------

Building Mono on Win32/Cygwin
=============================

(1) Install Cygwin

Run setup-x86.exe to install Cygwin   -   
http://www.cygwin.com/setup-x86.exe

Follow instructions from "Compiling Mono on Windows" to install needed
packages

http://www.mono-project.com/Compiling_Mono_on_Windows

autoconf
automake
bison
gcc-core
gcc-g++
mingw-gcc
libtool,
make
python,

Also nice to haves: wget, zip patch, openssh, vim

NOTE: In addition to this you will need the following packages as per
these instructions

http://www.codeproject.com/Articles/19575/Building-Mono-on-Windows-the-final-battle

gettext-devel
intltool
libiconv
pkg-config

2) Install working Mono binaries

Use the installation executable from go-mono.com, at time of writing:

http://download.mono-project.com/archive/3.2.3/windows-installer/mono-3.2.3-gtksharp-2.12.11-win32-0.exe

For me this gives a working Mono in C:\Program Files (x86)\Mono-3.2.3 on
a Windows 8.1 / x64 host

(3) Grab new Mono sources

(a) From source tarball

(i) Download and Extract

Download the tarball you wish to use from
http://download.mono-project.com/sources/mono/

NB. I have had different build issues with different Mono releases at
different times, on differing platforms,
to paraphrase Mrs Gump, "Mono is like a box of chocolates, you never
know what you are going to get"

At the time of writing we are using 3.4.0:
http://download.mono-project.com/sources/mono/mono-3.4.0.tar.bz2

Do not extract the source tarball with native Window tools as this
appears to affect line endings, which will cause problems.

To extract within Cygwin first run the Cywgin environment (Cygwin
terminal on your start bar) and extract with,

tar xjvf mono-3.4.0.tar.bz2

This will give you a mono-3.4.0 directory

(ii) Mount destination

Create a destination folder, where we are going to install the newly
built Mono, in this case C:\Mono-3.4.0

Copy across files from your existing installation (e.g. Mono-3.2.3) to
the 3.4.0 folder to give us a baseline

NOTE: It is important not to have spaces in the path as otherwise the
Mono build will fail, so we're putting this in the root of C: for this
example
           (From my reading it is also likely to be important not to
have Windows user names with spaces in them, so a heads-up there...)

Mount this folder as /usr/local with

mount "C:\Mono-3.4.0" /usr/local

As a check you can 'ls /usr/local' which should show the files that you
have in C:\Mono-3.4.0

(iii) Autogen the build

./autogen.sh --prefix="C:\Mono-3.4.0" --with-preview=yes

(iv) Configure the build

./configure --host=i686-pc-mingw32

At the end of this process, with the defaults, you should see something like

        mcs source:    mcs

   Engine:
        GC:            sgen and bundled Boehm GC with typed GC and
parallel mark
        TLS:           pthread
        SIGALTSTACK:   no
        Engine:        Building and using the JIT
        oprofile:      no
        BigArrays:     no
        DTrace:        no
        LLVM Back End: no (dynamically loaded: no)

   Libraries:
        .NET 2.0/3.5:  yes
        .NET 4.0:      yes
        .NET 4.5:      yes
        MonoDroid:     no
        MonoTouch:     no
        Xamarin.Mac:   no
        JNI support:   no
        libgdiplus:    assumed to be installed
        zlib:          system zlib

(v) We're ready to build mono

You can go ahead and try 'make' now but at the time of writing
(03/05/2014) there is a problematical interaction between the Cygwin
headers and the Mono build

This will lead to an error along the lines of,

/usr/i686-pc-mingw32/sys-root/mingw/include/ddk/ntapi.h:49:15: error:
conflicting types for 'PEXECUTION_STATE'
In file included from
/usr/i686-pc-mingw32/sys-root/mingw/include/windows.h:62:0,
                 from
/usr/i686-pc-mingw32/sys-root/mingw/include/winsock2.h:40,
                 from ../../mono/io-layer/io-layer.h:24,
                 from ../../mono/metadata/domain-internals.h:15,
                 from ../../mono/metadata/metadata-internals.h:8,
                 from ../../mono/metadata/class-internals.h:10,
                 from ../../mono/metadata/object-internals.h:8,
                 from process.c:16:

A workaround is to edit the Cygwin header file ntapi.h (e.g.
C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\include\ddk\ntapi.h) to
rename PEXECUTION_STATE to PEXECUTION_STATE_KLUDGE, say.

Then,

make

(this will take some time )

(vi) Install mono

At the time of writing (04/05/2014) there is a missing file in the Mono
3.4.0 release tarball. This causes installation failure.

ref:
http://stackoverflow.com/questions/22844569/build-error-mono-3-4-0-centos

To add the missing file create a new file in  mcs/tools/xbuild/targets/
called Microsoft.Portable.Common.targets

This should contain the following

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\Microsoft.Portable.Core.props" />
<Import Project="..\Microsoft.Portable.Core.targets" />
</Project>

Then ensure that /usr/local is correctly mounted as per 3(b)(ii) and run

make install

(vii) Fix "missing" mono.exe

The installation removes the existing mono.exe from the
C:\Mono-3.4.0\bin directory and does not seem to copy across a new version

Within the Cygwin environment there is a "mono.exe" which is a symbolic
link to mono-sgen.exe, which is rebuilt.

So, assuming that under Win32 the mono.exe is a stub executable (which
it seems to be as it is small) it should be reasonable to copy  across
mono.exe from the older mono installation

e.g. Copy C:\Program Files (x86)\Mono-3.2.3\bin\mono.exe to
C:\Mono-3.4.0\bin

(vii) Check installation

Open a Windows cmd box, cd to C:\Mono-3.4.0 and run

mono --version

This should show something like

Mono JIT compiler version 3.4.0 (tarball)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors.
www.mono-project.com
        TLS:           normal
        SIGSEGV:       normal
        Notification:  Thread + polling
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

(viii) Enable Xamarin Studio to add the new Mono runtime

If you to to Xamarin Tools->Options and try to add the Mono-3.4.0 folder
it will fail to detect Mono.

This is because of the presence of an installed symlink file, bin\mono

So, for example, delete the file C:\Mono-3.4.0\bin\mono and you will
then be able to add the runtime to Xamarin Studio

There is an archive of the binaries resulting from my build here,

http://www.dynamicdevices.co.uk/downloads/Mono-3.4.0.zip

NOTE: That Mono 3.x fails to build projects for me with recent Xamarin
Studio builds giving the error

Build failed. Could not find type 'System.Globalization.SortVersion'.

This appears to be addressed in this commit which is not present in 3.4.0

http://stackoverflow.com/questions/23448795/build-failed-could-not-find-type-system-globalization-sortversion

The workaround is to use an older version of Xamarin Studio as discussed
here

http://stackoverflow.com/questions/23448795/build-failed-could-not-find-type-system-globalization-sortversion

i.e. Download Xamarin Studio 4.2.3 from your account at Xamarin.com with
"view all versions"

NOTE: You may then get a build error about UNC paths

error : Error building target GetReferenceAssemblyPaths: UNC paths
should be of the form \\server\share.

This appears to relate to extra \\'s in configuration files as discussed
here

http://stackoverflow.com/questions/19933266/error-building-c-sharp-solution-using-xbuild-mono

The workaround is to go to project options and unback "Use MSBuild
engine" at which point you will be able to compile and debug applications

(b) From SVN  - TBD

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140504/892610fc/attachment-0001.html>


More information about the Mono-devel-list mailing list