Skip to content

Windows Development

jczech edited this page Feb 3, 2015 · 4 revisions

Introduction

The code development is made to be cross-platform. Originally this only meant all POSIX-compatible systems. Recently Windows support was added by adding a few wrapped and emulated functions and changing a few features.

Program Differences

Currently the there are a few differences between the Windows program and other platform programs. These are mainly due to the underlying platform differences.

  • Does not support user signals (TODO: eventually support some equivalent system using sockets or mutex)
  • Supports paths with either / or \ for folder separators which means that a MDL file may work on Windows but not *nix
  • Does not support symlinks on Windows XP or earlier. (Note: As of 2/3/15, symlinks do not seem to work on Win8)

What You Must Do

As a developer you must be aware of a few things to make sure it stays Windows-compatible.

  • First coding line must be #include "config.h" which is necessary to always make sure every file has the same environment
  • For functions that take printf-like format strings you must use PRINTF_FORMAT(#) or PRINTF_FORMAT_V(#) (see logging.h for examples)
  • Any code that is specific to Windows must be surrounded with #ifdef _WIN32 / #endif
  • Some POSIX-like functions in Windows required wrapping to add additional features and have additional constraints:
    • In general you cannot depend on the same errno to be set as on real POSIX systems and some of the edge-cases may be off
    • strerror_r - return value is POSIX-like (not GCC-like) (strerror_s is used)
    • ctime_r - must be given a fixed-sized on-stack char buffer (something you can nicely use sizeof on) (ctime_s is used)
    • strftime - (adds support for many of the additional format string)
    • gethostname - (adds special initialization during the first call)
    • stat - (adds support for symlink detection)
    • rename - (adds support for atomic rename)
    • mkdir - mode argument is ignored (adds the mode argument to the declaration)
  • Some POSIX functions are completely missing on Windows, have been emulated, and have additional constraints:
    • In general you cannot depend on the same errno to be set as on real POSIX systems and some of the edge-cases may be off
    • getrusage - only supports RUSAGE_SELF, output struct only has ru_utime and ru_stime, errno not always set and cannot include <sys/resource.h> (so do #ifndef _WIN32 / #include <sys/resource.h> / #endif)
    • symlink - always fails on Windows XP and earlier (which don't support symbolic links)
    • alarm - return value is not correct, must use set_alarm_handler instead of sigaction (TODO: finish creating and testing)
  • Many POSIX functions are not available or are not the same, a wrapped or emulated function may need to be added
  • User signals are not supported at all
  • Pathnames can contain either / or \ for folder separators and must be handled appropriately

The file "config-win.h" contains the POSIX-compatibility functions listed above.

Compiling on Windows

If you are compiling on a Windows machine you must use the MinGW-w64 compiler. Currently the original MinGW compiler and Microsoft Visual C compiler cannot be used.

NOTE: Currently this is difficult. You have to have a few files generated on a Linux machine or use Cygwin (both of which are not covered here).

TODO: Write up a Cygwin guide.

  1. You need to install 7-zip first to be able to extract the download below
  2. Copy the files "config.h", "version.h", "mdllex.c", "mdlparse.h", and "mdlparse.c" from a source made on a Linux machine (will need to be re-copied if the .l/.y files change)
  3. Download MinGW-w64 for your system:
  4. Extract the archive somewhere (for example "C:")
  5. Double-click the file "mingw32env.cmd" or "mingw64env.cmd" in that folder
  6. Type cd /d C:\Path\To\mcell\src replacing C:\Path\To\mcell\src with the path to the MCell source folder, then press Enter
  7. Type gcc -mconsole -std=c99 -O3 -fno-schedule-insns2 -Wall -Wshadow -o mcell.exe *.c then press Enter

If you would like a more permanent compiling solution on Windows, I suggest you extract them to "C:\Program Files" and add the "bin" folder in there to your path. You can have both 32-bit and 64-bit compilers on your system at the same time and use both from the path by using the prefixed versions of the programs (e.g. "i686-w64-mingw32-gcc" or "x86_64-w64-mingw32-gcc").

Cross-Compiling on Linux

It is actually easier to cross-compile on a Linux machine due to being able to use make, bison, and wget.

  1. Install all prerequisites of MCell compiling (e.g. bison)
  2. Install the mingw-w64 GCC packages for both i686 and x86_64 architectures (probably called mingw64-i686-gcc and mingw64-x86_64-gcc)
  3. Go to the mcell/src folder and run the following commands:
    1. ./bootstrap
    2. mingw32-configure
    3. mingw32-make
    4. Rerun the last two commands with "mingw64" prefix instead of "mingw32" to compile for 64-bit (some systems may use the prefixes mingw64-i686 and mingw64-x64_64 instead of mingw32 or mingw64)
Clone this wiki locally