[Mono-dev] compile mono on windows

Frank Fuchs fk.fuchs at googlemail.com
Fri Apr 15 16:51:53 EDT 2011


After some more successful tests I can confirm that I build a more or less functional version of a 64 bit native Windows mono runtime using Mingw-w64 and MSys (without cygwin). Initially I targeted mono.2.10.1 but ended up with some runtime errors (I had been warned that it might not work out with Win64).  Therefore, I switched back to 2.6.7. I wrote down a memory protocol of what I did in order to get it up and running. I know that most of my changes to the source are not very clean, anyway I'd like to share them in this collected fashion in order to help people out with this. Maybe someone could enhance this or even incorperate it to the "compiling mono for windows" section on the mono homepage. 

Thanks to all the people who somehow contributed!
Frank

As far as I understand it: Mono consists of the runtime and libs (mono) and a C# compiler (mcs, gmcs, dmcs). 
The latter one is an cil-assembly itself. Therefore it can change its bitness (32/64 bit) depending on the runtime - so we don't have to build this part. 

1. Download the tarball & 32 bit release (at the moment 2.6.7 works best for embedding and 64 bit, at least for me)
2. get all dependencies and build tools
Mingw-w64 (targeting 64 bit of course, TDM has very complete builds http://tdm-gcc.tdragon.net/download) 
in the following the install-path will be called MINGW_PATH (you should substitute every occurrence with your personal Mingw-path)
get MSys (e.g. the convience bundle provided by the Mingw-w64 guys (don't worry that it's 32 Bit) http://goo.gl/Z5lxC )
in the following the install-path will be called MSYS_PATH (you should substitute every occurrence with your personal MSys-path)
install automake (if think I used the MSys automake against all warnings)
get 64 bit versions of pkg-config and glib.2.26 (incl. dev-package, for mono.2.6.7 it's required) from http://www.gtk.org/download-windows-64bit.html and extract them to $MINGW_PATH  
Start working in an MSys shell 
export PATH=MINGW_PATH/bin:MSYS_PATH:$PATH - the ordering is important as there might be duplicates between Mingw-w64 and MSys
get zlib and compile it (http://zlib.net/zlib-1.2.5.tar.gz) and build: 
make -f win32/Makefile.gcc 
install as follows: cp -iv zlib1.dll $MINGW_PATH/bincp -iv zconf.h zlib.h $MINGW_PATH/includecp -iv libz.a $MINGW_PATH/libcp -iv libzdll.a $MINGW_PATH/lib/libz.dll.

3. get the Boehm GC in a mingw-w64 compatabile form (http://gitorious.net/w64/bohem-gc?page=9) and build it: 
./configure --prefix==MINGW_PATH ; make ; make install 
4. extract the mono directory and patch the following files:
modify build-mingw32.sh:
modify the path variables:
MINGW=x86_64-w64-mingw32
CROSS_DIR=MINGW_PATH
INSTALL_DESTDIR="$CURDIR/mono-win32"
CROSS_BIN_DIR="$CROSS_DIR/bin"
CROSS_DLL_DIR="$CROSS_DIR/bin"
CROSS_PKG_CONFIG_DIR=$CROSS_DIR/lib/pkgconfig
modify the first configure line:
../configure --prefix=$MONO_PREFIX --with-crosspkgdir=$CROSS_PKG_CONFIG_DIR --target=$MINGW --host=$MINGW --enable-parallel-mark --program-transform-name="" --disable-mcs-build --enable-nls=no --with-tls=no --with-gc=boehm
# we use the Boehm GC and disable the native language support (nls), also we don't build the MCS here
comment out the second configure line and make
modify libgc/include/gc.h (ripoff from http://goo.gl/QDOWw)
--- mono-2.6.7.orig/libgc/include/gc.h  
+++ mono-2.6.7/libgc/include/gc.h   
@@ -61,8 +61,13 @@
   /* Win64 isn't really supported yet, but this is the first step. And */
   /* it might cause error messages to show up in more plausible places.    */
   /* This needs basetsd.h, which is included by windows.h.     */
+#ifdef __int64
   typedef unsigned __int64 GC_word;
   typedef __int64 GC_signed_word;
+#else
+  typedef unsigned long long GC_word;
+  typedef long long GC_signed_word;
+#endif
 #endif
modify libgc/include/gc_config_macros.h
@@ -124,7
-  #if defined(_DLL) && !defined(GC_NOT_DLL) && !defined(GC_DLL) 
+ #if defined(_DLL) && !defined(GC_NOT_DLL) && !defined(GC_DLL) \
+   && !defined(__GNUC__)
# define GC_DLL
#endif
modify mono/mini/driver.c (a shortcut to the solution from http://goo.gl/QDOWw)
@@ -1239,7
 #ifdef HOST_WIN32
 BOOL APIENTRY DllMain (HMODULE module_handle, DWORD reason, LPVOID reserved)
 {
//if (!GC_DllMain (module_handle, reason, reserved))
//    return FALSE;
modify mono/mini/driver.h
@@ 5
+ #include <sys/types.h>        // include for pid_t
modify mono/metadata/coree.c @@ -26,7
#ifndef _MSC_VER
+#ifdef __MINGW64_VERSION_MAJOR
+#define __ImageBase __MINGW_LSYMBOL(_image_base__)
+#else
#define __ImageBase _image_base__
+#endif
#endif

modify io-layer.h
@@ 40,7
#else /* !_MSC_VER */
- #include <ddk/ntddk.h>
- #include <ddk/ntapi.h>
+ //#include <ddk/ntddk.h>
+ //#include <ddk/ntapi.h>
#endif /* _MSC_VER */

modify boehm-gc.c
@@ 125,7
+   GC_allow_register_threads();   // required for external Boehm GC

modify mono/profiler/mono-profiler-aot.c (strangely the PLATFORM_WIN32 does not kick in here)
@@ 68
#ifdef PLATFORM_WIN32
   err = mkdir (tmp);
#else
-  err = mkdir (tmp, 0777);
+    err = mkdir (tmp);    
#endif
5. run build-mingw32.sh and enjoy 
for me on one of my build machines there were linking errors for the shared libraries (libmono.dll) because lmswsock and others are missing,
I just copied the files from C:/Windows/System32 to MINGW_PATH/bin adding the lib prefix (mswsock.dll -> libmswsock.dll)
after make install (build-mingw32.sh should do it) you should have a 64 bit runtime & libraries
6. merge the contents of your newly compiled installation folder (see build-mingw32: INSTALL_DESTDIR="$CURDIR/mono-win32") with the released tarball.
I just copied mono-win32/* into the unziped release, added the 64 bit glib & glib-dev and deleted all files except lib/mono/* which had the date of the release
7. go ... and have fun (and if you find some time ... please complete this manual)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110415/3e01f2ce/attachment-0001.html 


More information about the Mono-devel-list mailing list