Find file
Fetching contributors…
Cannot retrieve contributors at this time
252 lines (165 sloc) 9.4 KB
Mercury has been ported to use the Microsoft Visual C++ compiler.
It has been tested with versions 9.0 (2008) through 12.0 (2013).
Version 8.0 (2005) should also work but we have not tested that with Mercury
A Unix-like environment is required for building and installing Mercury.
Either Cygwin <> or MSYS <> will
suffice for this purpose.
A Unix-like environment is *not* required in order to use Mercury once it
has been installed.
To make MSVC and its supporting tools available under the Cygwin or MSYS shells
do the following:
(1) Open the Visual Studio Command Prompt.
This can typically be found in
Start -> Visual Studio YYYY -> Visual Studio Tools
although the name and location vary between different versions and editions
of Visual Studio. (YYYY is the year.)
(2) Enter the following command to start the MSYS shell:
C:\> C:\MinGW\MSYS\1.0\msys.bat
or this one to start the Cygwin shell:
C:\> C:\CYGWIN\cygwin.bat
(We assume the default installation locations for MinGW/MSYS and Cygwin above.)
In order to install the C#, Erlang or Java grades you will require a C#,
Erlang or Java compiler to be included in the Windows PATH.
(See the relevant README files for further details, e.g. README.Java etc)
The Makefile for the Boehm garbage collector requires the files NtWin32.Mak and
Win32.Mak to be present in the build environment. These files are *not*
included with Visual Studio 2013 and must be copied or included from the
Windows 7 (or 7.1) SDK.
To include the above files, append the SDK directory to the end of the INCLUDE
environment variable, for example (with the Windows 7.1 SDK):
C:\> set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1a\Include
Alternatively, you can just copy the NtWin32.Mak and Win32.Mak files into the
"boehm_gc" directory of the Mercury source tree.
The MSVC port of Mercury is compatible with the prebuilt C files contained in
the Mercury source distribution. The 'asm_fast' and 'reg' grades will not work
with MSVC (see below). When using the prebuilt C files the compiler will be
built in the 'none.gc' grade.
Alternatively, if you have an existing Mercury installation that uses the MinGW
or Cygwin GCC ports, or clang then you can checkout the Mercury source from the
CVS repository and use your existing installation to cross-compile the MSVC
port. In this case the compiler will be built using the more efficient
'hlc.gc' grade.
In either case, to use MSVC as the C compiler with Mercury, invoke configure
as follows:
$ ./configure --with-cc=cl [--with-msvcrt] [<any other options>]
The `--with-msvcrt' flag causes executables built with this install of Mercury
to be linked with the MS Visual C runtime, instead of the standard libC
On Cygwin, configure and mmake will do translation of Unix style paths, so you
may specify the installation directory using either a Unix- or Window-style
path. On MSYS, you must use a full Windows-style path with a drive letter,
except that you must use '/' instead of `\' as a directory separator.
For example, this is acceptable:
$ ./configure --prefix="c:/where/to/install/mercury"
whereas the following is not:
$ ./configure --prefix="c:\where\to\install\mercury"
Once configure has successfully finished, then you should do
$ make
$ make install
as normal.
The MSVC port currently has a number of limitations:
* The 'asm_fast' and 'reg' grades do not work with MSVC.
Both use GNU extensions to C that MSVC does not provide.
* Time profiling does not (currently) work with MSVC.
Time profiling grades (those whose name contains the 'prof' grade component)
will not be installed.
Note that memory profiling _does_ work with MSVC. (Memory profiling grades
are those whose name contains the 'memprof' grade component.)
* Parallel grades (those whose name contains the `par' component) do not
currently work with MSVC.
In parallel grades the Mercury runtime currently requires the use of POSIX
threads; it has not currently been ported to use Windows threads.
(It might be possible to use the pthreads-win32 library with MSVC to
provide POSIX threads but we have not tested that yet.)
* Deep profiling, e.g. the *.profdeep grades, does not (currently) work
with MSVC. (In principle, it should work if the clock tick metric is
* The deep profiling tool (mdprof_cgi) does not currently work with MSVC.
This is due to it containing a number of Unix dependencies. (Other
tools that work with deep profiles should be fine.)
* Generation of 64-bit code using Mercury and MSVC is not yet supported.
To generate native 64-bit executables on Windows you will need to use
the MinGW64 port (see README.MinGW for details).
* When used directly from the Windows command prompt, mmake will not work.
You should use `mmc --make' instead. (mmake requires a POSIX-like shell
and GNU make; it will however work with the Cygwin or MSYS shells.)
Note that we have no intention of ever supporting mmake directly on
* Creation of shared libraries (DLLs) is not currently supported.
* The '--c-debug' option currently has no effect with MSVC since enabling
it breaks parallel builds and disables some C compiler optimizations.
If you *really* want to enable support for C level debugging, then enable the
commented out definition of DEBUG_OPTS in scripts/ (in the "cl" case)
and also enable the commented out definition of CFLAGS_FOR_DEBUG in (in the "msvc*" case). You will then need to regenerate
the configure script and rebuild the Mercury system. (See INSTALL.git for
details of how to do this.)
The above instructions create a Mercury installation that targets MSVC that
works from within the Cygwin or MSYS shells. If you want to be able to run the
Mercury compiler directly from the Windows command prompt (e.g. cmd.exe)
then you need to manually edit some configuration files in the installation.
(In future releases, this will all hopefully be automated.)
All references to files in the following are within the Mercury installation
* By default, the Mercury compiler will attempt to use the "cp" command to
install files. Since Windows does not provide this, you will need to provide
an alternative (see the next section for details of how to do this).
We recommend installing the UnxUtils port of "cp" and using that with
Mercury. See: <>.
* In the file lib/mercury/conf/Mercury.config:
+ Replace any Unix-style paths with their Windows-style equivalent.
+ Modify the values of the options --host-env-type and --target-env-type
in the value of the variable DEFAULT_MCFLAGS so that their values are as
--host-env-type "windows"
--target-env-type "windows"
+ To specify the commands used to install files and directories include
the following options in the value of the variable DEFAULT_MCFLAGS
--install-command <cp>
--install-command-dir-option <opt>
(NOTE: if you are using the UnxUtils port of "cp" then you don't need to
do anything here; the default settings will suffice.)
* In the file lib/mercury/mdb/mdbrc
+ The backslash character, `\`, is used as an escape character in mdbrc
files. You need to escape it if it occurs in any paths used in the
argument of source commands, for example
source c:\mercury-11.07\lib\mercury\mdb\mdb_doc
needs to be replaced with:
source c:\\mercury-11.07\\lib\\mercury\\mdb\\mdb_doc
+ Delete the aliases for the "open" and "grep" commands.
The scripts that implement these commands assume a Unix-style environment.
* The bin directory contains batch files equivalent to the mmc, mdb and prof
scripts. Note that the batch file equivalent to the mmc script is named
mercury.bat in order to avoid clashing with the executable for the
Microsoft Management Console.
* The following scripts do not currently have a Windows equivalent.
+ mprof_merge_runs
+ mtc
* The other shell scripts in the bin directory do not have (or need) Windows
equivalents. (Most of them are part of the implementation of mmake which
is not supported on Windows systems.)
If you want to install on the machine, foo, in the directory \usr\local
you need to add `--prefix //foo/usr/local' as an option to configure.
Then ensure that the directory that you wish to install into is mounted
somewhere, i.e.
mount //foo/usr/local /temp_mount_point
and then use that mount point as the location to install into
make install INSTALL_PREFIX=/temp_mount_point
This avoids the problem that
mkdir -p //foo/usr/local/xxx