Compiling Metropolis with MinGW

MinGW is Minimalist GNU For Windows, see http://www.mingw.org

The advantage of MinGW is that it is between Micrsoft Visual C and Cygwin in that MinGW can link to most MSVC .lib files. It is sometimes easier to port multithreaded programs to MinGW before porting to either MSVC or Cygwin.

In December, 2003, we used MinGW 3.1.0 to compile the producers_consumer example.

Below is how we did it

Installing MinGW

  1. Download MinGW-xxx.exe from the current section of target="_top">http://www.mingw.org/download.shtml. We downloaded MinGW-3.1.0-1.exe
  2. Click on the .exe file and install MinGW in c:\mingw

Compiling SystemC with MinGW

  1. Install the cygwin patch binary by rerunning Cygwin setup.
  2. Untar systemc-2.0.1
  3. Download SystemC MinGW patches from http://www.systemc.org/tracker/index.php?func=detail&aid=83&group_id=5&atid=107
    I had to strip out the Control-M characters using emacs.
  4. Patch
    patch -p 1 < c:/tmp/downloads/systemc-mingwin-patch-2 
    
  5. Set you your path to include the mingw gcc
    bash-2.05b$ PATH=/cygdrive/c/mingw/bin:${PATH}
    bash-2.05b$ export PATH
    bash-2.05b$ which gcc
    /cygdrive/c/mingw/bin/gcc
    bash-2.05b$ gcc -v
    Reading specs from c:/mingw/bin/../lib/gcc-lib/mingw32/3.2.3/specs
    Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c++,f77,objc --disable-win32-registry --disable-shared --enable-sjlj-exceptions
    Thread model: win32
    gcc version 3.2.3 (mingw special 20030504-1)
    bash-2.05b$ 
    
  6. Run make -f Makefile.MinGW
  7. I got an error:
    Makefile.MinGW:143: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.
    
    I had to edit the Makefile.MinGW path add trailing \ to a bunch of lines
  8. Run make -f Makefile.MinGW again
  9. I got another error:
    g++ src/systemc/kernel/sc_cor_fiber.cpp
    src/systemc/kernel/sc_cor_fiber.cpp: In destructor `virtual 
       sc_cor_fiber::~sc_cor_fiber()':
    src/systemc/kernel/sc_cor_fiber.cpp:63: `GetCurrentFiber' undeclared (first use  this function)
    
    The problem is that c:/mingw/include/winnt.h includes decls for GetCurrentFibre
    Solution: edit src/systemc/kernel/sc_cor_fiber.cpp and add
    #ifdef __MINGW32__
    #include 
    #endif 
    
  10. Rerun make -f Makefile.MinGW, and libsystemc.a should be created.
  11. Create a lib-mingw directory and move the libraries:
    mkdir lib-mingw
    mv *.a lib-mingw
    

Build Metropolis

  1. $METRO/src/metropolis/metamodel/backends/systemc requires getrusage() which is not usually part of Windows. To compile port_rusage.cpp under MSVC, you must download psapi.h and psapi.lib. To run, you probably need psapi.dll. The easiest way to obtain these files is to look for them on the web using Google.
    psapi.h and psapi.lib should be placed in $METRO/src/metropolis/metamodel/backends/systemc.
    psapi.dll should be placed in your C:\Windows directory.
  2. Configure Metropolis, use --with-systemc to include the MinGW version of SystemC. I used:
    PATH=/cygdrive/c/mingw/bin:${PATH}
    export PATH
    cd $METRO
    rm config.*; ./configure --with-systemc=c:/cxh/src/systemc-2.0.1-mingw --with-systemc-lib=lib-mingw
    
  3. Run make with the same flags that were used to compile SystemC under MinGW
      make LIBS=-lpsapi CXX_USERFLAGS="-mthreads -mms-bitfields -MMD"
    
    If you do not use the proper flags, then when you try to link the producers_consumer example, you might see:
    c:/cxh/src/metro/src/metropolis/metamodel/backends/systemc/liblibrary.a(global.o)(.rdata$_ZTI15sc_signal_in_ifIN5sc_dt8sc_logicEE+0x0): In function `ZThn4_NK9sc_signalIN5sc_dt8sc_logicEE4dumpERSo':
    c:/cxh/src/systemc-2.0.1-mingw/include/systemc/datatypes/bit/sc_logic.h: multiple definition of `typeinfo for sc_signal_in_if'