[Mono-dev] Compiling Mono 3.2.3 libraries - Windows/Visual Studio/32&64bit

BearishSun bearishsun at gmail.com
Sat Dec 7 09:25:52 UTC 2013


Hello,

I have managed to compile Mono 3.2.3. on Windows with Visual Studio 2012
using both 32bit and 64bit configurations but had some issues along the way.
As I have found little to none up-to-date information regarding this topic,
thought I'd share them with people in case anyone finds them useful. I have
only compiled the native libraries (mono-2.0.dll, mono.exe). Here goes:

1. Visual Studio solution is located inside msvc folder of Mono source
distribution, but it needs some fixes to get it working.
2. 3.2.3 version is missing "mono.props" file and without it Visual Studio
will fail to open some project files. To fix download the .props file from
https://raw.github.com/mono/mono/master/msvc/mono.props and put it in
mono-3.2.3\msvc folder before opening any projects or solution
3. Even though solution is VS2010, it will only compile with VS2012 unless
you change platform toolkit to v10 for all projects. (Haven't actually
tested with VS2010)
4. If compiler complains it cannot find pthreads.h make sure to define
"HAS_64BITS_ATOMIC" in libmonoutils project (for all configurations)
5. In dlmalloc.c change #include <dlmalloc.h> to #include "dlmalloc.h" if
compiler complains it cannot find that file
6. In "mono-proclib.c" add this bit of code somewhere near the start of the
file:

#ifdef HOST_WIN32
#define strtoll _strtoi64
#define strtoull _strtoui64
#endif

7. In "threads.c" replace a line in
ves_icall_System_Threading_Interlocked_CompareExchange_Long method, from:

return InterlockedCompareExchange64 (location, value, comparand);

    to

#ifdef HOST_WIN32
	return _InterlockedCompareExchange64 (location, value, comparand);
#else
	return InterlockedCompareExchange64 (location, value, comparand); 
#endif

    InterlockedCompareExchange64 is just a typedef for
_InterlockedCompareExchange64 on Windows and for some reason compiler
doesn't realize it (typedefs to intrinstics don't work?). Anyway, so we just
reference the intrinsic directly.

8. In "threads.c" replace a line in
ves_icall_System_Threading_Thread_VolatileRead8 method, from:

return InterlockedCompareExchange64 (ptr, 0, 0);
     
	to

#ifdef HOST_WIN32
	return _InterlockedCompareExchange64 (ptr, 0, 0);
#else
	return InterlockedCompareExchange64 (ptr, 0, 0);    
#endif

    Same problem as previous.

9. For all projects and configurations update their property pages under
"C/C++->Optimization" and set "Enable Intrinsic Functions" to "Yes"
    - You might be able to skip this step.
10. In "exceptions-amd64.c" replace line 121:

if (win32_chained_exception_needs_run) { 
    
   with

if (mono_win_chained_exception_needs_run) {

Delete lines 167 and 168:

if (old_win32_toplevel_exception_filter)
	SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter);

And move line 166 (line # after previous changes) to start of the function:

guint32 ret = 0;

11. In threads.c in mono_thread_get_stack_bounds method replace the bit of
code under "#if defined(HOST_WIN32)" from:

void* tib = (void*)__readfsdword(0x18);
guint8 *stackTop = (guint8*)*(int*)((char*)tib + 4);
guint8 *stackBottom = (guint8*)*(int*)((char*)tib + 8);

    to:

NT_TIB* tib = (NT_TIB*)NtCurrentTeb();
guint8 *stackTop = (guint8*)tib->StackBase;
guint8 *stackBottom = (guint8*)tib->StackLimit;

    __readfsdword doesn't exist when building 64bit. Use may use
__readgsqword instead but then you need
	to double all your offsets. NtCurrentTeb works equally for both 32 and 64
bit builds.

12. You are done. Hopefully this helps someone!



--
View this message in context: http://mono.1490590.n4.nabble.com/Compiling-Mono-3-2-3-libraries-Windows-Visual-Studio-32-64bit-tp4661474.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list