Compilation with MinGW

I’m trying to build ROOT for Windows using MinGW compiler. After some tries, I finally got it compiled.
Everyrhing happened under Windows 7 Ultimate with Visual Studio 2010 installed. That’s how I did this:

  1. I installed latest Cygwin (standard installation+make package) and full MinGW stuff(gcc 4.6.2)

  2. I downloaded ROOT sources from svn(I used 5.32/03 version)

  3. I configured ROOT sources for win32 build from cygwin terminal. To do that, I needed to set up
    the correct VS system variables. I simply executed vcvarsall.bat file from windows command line, checked
    which system variables it adds/modifies and wrote simple script cygwin_setvcvars.sh to do that from cygwin. Script is called by

    source cygwin_setvcvars.sh

    from cygwin terminal. After that, I was able to run configure script:

    ./configure win32 --minimal --build=release
  4. The next step is to modify scripts for compiling to make them call gcc instead of cl. I changed the
    following files:

    build/win/cl.sh build/win/ld.sh build/win/makelib.sh

  5. I had to add 2 header files to include directory from Windows SDK include directory. These files are

    sehmap.h ( to ./include and . ) dbghelp.h ( to ./include )

  6. I had to change cint/cint/Module.mk file in order to use gcc implementation of STL instead of
    Microsoft’s one. I changed line 123 of that file from

 CINTS2       += $(MODDIRSD)/vc10strm.cxx

to

CINTS2 := $(filter-out $(MODDIRSD)/libstrm.%,$(CINTS2)) CINTS2 += $(MODDIRSD)/gcc4strm.cxx
and also copied TAtomicCountGcc.h from ./core/thread/inc to ./include
7. I had to modify sources a bit:

In file cint/cint/src/newlink.cxx, line 81, from
[code]extern[/code]
to
[code]#ifndef G__MINGW_COMPILATION
extern
#endif[/code]
In file G__ci.h, line 379, from
[code]#if defined(G__WIN32) && !defined(__CINT__)[/code]
to
 #if defined(G__WIN32) && !defined(__CINT__) && !defined(G__MINGW_COMPILATION)
In file include/TCollectionProxyInfo.h, line 27, from
[code]#if defined(_WIN32)[/code]
    to
    [code]#if defined(_WIN32) && !defined(G__MINGW_COMPILATION)[/code]
In file w32pragma.h, line 64, from
	[code]#define WINVER 0x0400[/code]
to
[code] #define WINVER 0x0501[/code]
In file core/textinput/src/textinput/TerminalDisplayWin.cpp, at line 20, added
[code]#include<stdio.h>[/code]
    In file core/textinput/src/textinput/StreamReaderWin.cpp, at line 21, added
[code]#include <ctype.h>[/code]
In file core/base/inc/DllImport.h, line 22, from
[code]# if defined(WIN32)[/code]
to
[code]# if defined(WIN32) && !defined(G__MINGW_COMPILATION)[/code]
In file graf2d/win32gdk/src/TGWin32Gl.cxx, at line 34, added
[code]#ifdef G__MINGW_COMPILATION

#include <GL/glext.h>
#endif[/code]
In file graf2d/win32gdk/src/TGWin32ProxyDefs.h, line 38, from
static enum { kDebugProfile = -123, kDebugTrace = -1234 };
to
#ifndef G__MINGW_COMPILATION static #endif enum { kDebugProfile = -123, kDebugTrace = -1234 };
In file graf2d/win32gdk/gdk/src/gdk/win32/gdkprivate-win32.h, line 433, from
#ifdef __GNUC__
to
#if defined( __GNUC__ ) && ! defined( G__MINGW_COMPILATION )
In file core/winnt/src/TWinNTSystem.cxx, line 3060, from
Printf("Which: %s = %s", infile, name);
to
Printf("Which: %s = %s", (const char*)infile, name);
Also in that file I had to modify inline assembler from MSVC style to gcc style.

  1. I had to modify makefiles:

    graf2d/freetype/src/win/freetype.mak core/pcre/src/win32/Makefile.msc graf2d/win32gdk/gdk/src/gdk/win32/makefile.msc graf2d/win32gdk/gdk/src/gdk/makefile.msc
    and add a script copy_objs.sh to .

  2. for some reason, while running makefile, some files have incorrect access rights, so I first run make,
    stopped it just after it finished copying files and started actual compilation, and then applied

 chmod a+r

to files in include/Fit and include/Math

  1. Finally, I ran
    make

from cygwin terminal. It finished successfully, the full log is in file make.log.

  1. After that, I set ROOTSYS system variable, ran
    make -n install
    to see what’s happening during installation and copied printed commands to install.sh script. Then I ran
    ./install.sh

After all actions I’ve just described, I tried to run ROOT, both from cygwin and windows. The ROOT logo window is shown in both cases. If started from command line, then ROOT intro appears:

[code] *******************************************

  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.32/03 9 May 2012 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      http://root.cern.ch            *
    
  •                                     *
    

ROOT 5.32/03 (Dec 24 2012, 19:26:31@44167, Dec 24 2012, 19:31:06 on win32)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.[/code]
But the “[0]” command line doesn’t appear. If I type commands (I tried simply “?”), nothing happens. If I start ROOT from windows, nothing appears after logo window, but the process root.exe is running (according to task manager), and some dlls are loaded(if I try to delete bin directory, messages of type “*.dll cannot be deleted baecuse it’s used by root.exe” appear).

The question is what is wrong with what I did? I don’t know much about how ROOT functions, but during
compilations I saw some utilities called, such as rmkdepend, rootcint_tmp and so on. Maybe they are functioning incorrectly because compilation is done with gcc? I’d be very thankful for every advice. Thanks a lot.

P.S. 7-zip archive with all the files I changed/added and compilation log is attached.
v5-32-03-cygwin-changes.zip (206 KB)

I finally got it to work. I built a debug version, went through it and found out, that the function GetConsoleMode didn’t work properly. Googling told me it was due to -mwindows -Wl,–subsystem,windows flags passed to linker. I wrote some test programs/dlls and found out, that it really affects only when linking an executable. So I modified cl.sh script and rebuilt ROOT. It started and passed some simple tests. Moreover, I built an xps package for R’s bioconductor using my ROOT build, and it also passed some tests. By the way, during the debug build I also modified TWinNTSystem.cxx file - I changed MSVC’s _ReturnAddress call to MinGW’s equivalent __builtin_return_address(0).

I also forgot ot say that I had to modify TGWin32ProxyDefs.h file - I changed line 19 from#define _NAME4_(name1,name2,name3,name4) _NAME3_(name1,name2,name3)name4 to #define _NAME4_(name1,name2,name3,name4) name1##name2##name3##name4 as for some reason(I don’t really understand why) MinGW’s preprocessor added an extra space before name4 and the build failed. Also I had to put sehmap.h file not only to ./include, but also to . folder.

The archive with the files I modified is attached. I think, it would be great if root developers will have a look at this, because my method was a little bit “barbaric” - I just modified sources/scripts to make it all work, but the right way would be to integrate it to the ROOT build system as a new configuration.
v5-32-03-cygwin-changes.zip (207 KB)

Dear ROOTers,

Since many years (since 2005) people are interested in a ROOT version built with MinGW, and a couple of people have tried to compile ROOT with MinGW. Now, finally Alexey has succeeded in compiling ROOT with MinGW and building a binary.

Since Alexey mentioned that he did some initial tests with my Bioconductor package xps which is based on ROOT, I would like to add that I have tested his binary, too, and it is running well on both Windows XP and Windows 7.

On Windows XP I could compare the running times of ROOT/xps built with MinGW with ROOT/xps built with MS VC++ 2010 Express Edition and I am glad to say that in all cases the MinGW build is slightly faster than the VC++ build, see the attached file ‘MinGWvsMSVC2010.txt’

For this reason, I would like to ask the ROOT developers to make this binary publicly available, and maybe to build future versions with MinGW, too (maybe as replacement of the cygwin version?)

Thank you in advance.

Best regards,
Christian
MinGWvsMSVC2010.txt (2.06 KB)

Dear Axel, dear Bertrand,

Although I did not yet receive any reply from you I did wait until now since I knew that you were busy with the ROOT User Workshop. I would really appreciate if you could make the MinGW binary from Alexey publicly available, so that users of my package xps can download it from your web-site or ftp-server.

Please allow me some further comments:

Not only did some users ask for a MinGW build of ROOT since some years, nowadays many Windows users request a 64 bit version of ROOT, which (as far as I understand) will not happen. For ROOT 6 Axel mentioned in slide 10 of his talk at the Workshop that supported platforms are ‘Linux (GCC compatible), MacOS - but not yet Windows!’.

I assume that as long as you stay with MS VC++ 64 bit support for ROOT and ROOT 6 will never happen. In contrast, using a development system based on MinGW may be the solution, especially since I could demonstrate that ROOT and my package xps compiled with MinGW are even slightly faster than the combination compiled with MS VC++.

Because of many problems with MS VC the R core developers have decided many years ago to replace MS VC with MinGW, and thus were able to provide stable 32 bit and 64 bit versions of R to Windows users. Some time ago the R developers have even created their own subset of MinGW, called Rtools (currently Rtools30.exe), which they use to compile R for all Windows versions (including Windows 8 64 bit), and which package developers using C/C++ use, too. Using the MinGW ROOT binary from Alexey, Rtools30.exe was all I needed to compile xps on Windows XP and Windows 7.

Why don’t you do something similar as the R developers and create your own subset of MinGW, called e.g. ROOTtools.exe, which in your case contains clang/llvm?

Best regards,
Christian