This file documents the port of Mercury to Windows that uses Microsoft Visual C++ (MSVC) as a C compiler.
With MSVC, you can install a Mercury compiler that generates either x86 (32-bit) or x64 (64-bit) Windows native code in C grades, but not both. (You can, of course, have multiple Mercury installations that use MSVC, and have one that targets x86 and another that targets x64.)
- Supported MSVC versions
- Setting up the build environment
- Configuration and installation
- Using Mercury in the MSYS2 or Cygwin shells
- Using Mercury in the Windows Command Prompt
- Limitations
You need version 19.3 or later of MSVC. Version 19.3 was included with Visual Studio 2022. Mercury is not supported with older versions of MSVC. Your Visual Studio installation needs the "Desktop development with C++" component to be installed.
You need a Unix-like environment to build and install Mercury. You can use either Cygwin or MSYS2.
You only need a Unix-like environment for the installation. You do not need one to run Mercury later.
To make the MSVC toolchain available in the Cygwin or MSYS2 shells, do the following:
-
Open the Visual Studio Command Prompt.
Go to the correct tool in your Start Menu:
Start Menu └── Visual Studio 2022 ├── x64 Native Tools Command Prompt for VS 2022 └── x86 Native Tools Command Prompt for VS 2022Select x64 to target 64-bit Windows or x86 to target 32-bit Windows.
If you prefer not to use the Start Menu shortcuts, then you can manually set up the environment variables by running one of the batch files supplied with Visual Studio (e.g.
vcvars32.batfor x86,vcvars64.batfor x64). -
Start the MSYS2 shell using this command:
C:\> C:\msys64\msys2_shell.cmd -use-full-pathOr start the Cygwin shell using this command:
C:\> C:\cygwin64\Cygwin.batWe assume the default installation locations for MSYS2 and Cygwin above.
To install the
csharpgrade, you must add a C# compiler to your WindowsPATH. See README.CSharp.md for further details.To install the
javagrade, you must add a Java compiler to your WindowsPATH. See README.Java.md for further details.
You can install the MSVC port of Mercury directly from the Mercury source distribution.
If you already have an existing Mercury installation that uses the MinGW-w64 ports of GCC or Clang, or one that uses the Cygwin port of GCC, then you can clone the Mercury source from the Git repository and use your existing installation to cross-compile the MSVC port.
When using MSVC, you must set the Mercury installation directory using the
--prefix option to configure.
-
Use a full Windows path with a drive letter (e.g.,
C:/mercury). -
Important: Use forward slashes (
/), not backslashes (\) as path separators (even though the latter is more usual on Windows).
For example, this is acceptable:
./configure --prefix="c:/where/to/install/mercury"
but this is not:
./configure --prefix="c:\where\to\install\mercury"
You must set the installation directory correctly, or the installation will fail.
Run configure as follows:
./configure --with-cc=cl --prefix=<install-dir> [<any other options>]
Once configure has successfully finished, then do:
make
and then:
make install
as normal.
This section describes how to use a Mercury compiler that was built using MSVC in the MSYS2 or Cygwin shells.
Check that the MSVC toolchain is in the Windows PATH and that the required
tools (cl, link and lib) are accessible from the Cygwin or MSYS2 shell.
Add the Mercury bin directory to the MSYS2 or Cygwin PATH using a
Unix-style path. For example, if Mercury is installed in "C:\mercury", then you
would add /c/mercury/bin to the MSYS2 PATH or /cygdrive/c/mercury/bin to
the Cygwin PATH.
After the Mercury bin directory has been added to the MSYS2 or Cygwin PATH,
then you should be able to use the Mercury compiler.
This section explains how to use Mercury that was built using MSVC in the
Windows Command Prompt (i.e. cmd.exe).
Make sure that the following are present in the Windows PATH:
-
The MSVC toolchain (
cl,linkandlib). -
The Java toolchain (
javac,jarandjava), if thejavagrade was installed. -
The C# toolchain (
csc), if thecsharpgrade was installed. -
The Mercury
bindirectory. For example, if Mercury is installed inC:\mercury, then you would addC:\mercury\binto the WindowsPATH.
You can then run the Mercury compiler using the command mercury.
This is a batch file that is the same as mmc in other environments.
We use the name mercury instead of mmc in the Windows Command Prompt.
This is because the name mmc is also used by the Microsoft Management
Console.
For example, to build the "Hello, World" example in the samples directory
of the Mercury distribution, do:
mercury hello.m
or, using the --make option:
mercury --make hello
Note that mmake is not supported in the Windows Command Prompt.
The MSVC port currently has the following limitations:
-
The
asm_fastandreggrades do not work. 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
.profgrade component) will not be installed.Memory profiling does work with MSVC. (Memory profiling grades are those whose name contains the
.memprofgrade component.) -
Parallel grades do not work because the Mercury runtime uses POSIX threads. It does not yet support Windows threads.
(It might be possible to use the pthreads-win32 library with MSVC to provide POSIX threads, but we have not yet tested that.)
-
Deep profiling (e.g. the
.profdeepgrades) does not (currently) work with MSVC. (In principle, it should work if the clock tick metric is disabled.) -
The deep profiling tool (
mdprof_cgi) does not currently work with MSVC. This is due to it containing Unix dependencies. (Other tools that work with deep profiles should be fine.) -
You cannot create libraries (DLLs) yet.
-
The
--c-debugoption is disabled 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_OPTSinscripts/mgnuc.in(for theclcase) and also enable the commented out definition ofCFLAGS_FOR_DEBUGinconfigure.ac(for themsvccase). You will then need to regenerate theconfigurescript and rebuild the Mercury system. (See INSTALL.git for details of how to do this.) -
mdb'sopenandgrepcommands do not work. The scripts that implement these commands only work on Unix-like systems. -
The following shell scripts included with the Mercury distribution do not work on Windows.
mprof_merge_runsmtc