-
Notifications
You must be signed in to change notification settings - Fork 11
Windows Development
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.
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)
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(#)
orPRINTF_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 usesizeof
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)
- In general you cannot depend on the same
- 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 supportsRUSAGE_SELF
, output struct only hasru_utime
andru_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 useset_alarm_handler
instead ofsigaction
(TODO: finish creating and testing)
- In general you cannot depend on the same
- 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.
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.
- You need to install 7-zip first to be able to extract the download below
- 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)
- Download MinGW-w64 for your system:
- download 32-bit (or more generally here)
- download 64-bit (or more generally here)
- Extract the archive somewhere (for example "C:")
- Double-click the file "mingw32env.cmd" or "mingw64env.cmd" in that folder
- 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 - 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").
It is actually easier to cross-compile on a Linux machine due to being able to use make, bison, and wget.
- Install all prerequisites of MCell compiling (e.g. bison)
- Install the mingw-w64 GCC packages for both i686 and x86_64 architectures (probably called mingw64-i686-gcc and mingw64-x86_64-gcc)
- Go to the mcell/src folder and run the following commands:
./bootstrap
mingw32-configure
mingw32-make
- 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)