Using Microsoft Visual C under Gygwin

It is possible to run Microsoft compiler from console: cl, link, lib, and other tools. However, I find the cmd environment (command tool supplied with Windows) rather primitive and prefer to work under Cygwin environment. Here it is also possible to use command line tools from the Microsoft Visual Studio but it is necessary to have path and environment variables set correctly.

In Visual Studio C++ there is a file vcvars32.bat (in my distribution it is C:\Programme\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat) that sets up path and environment under cmd. It well might be that these variables have been already set up at the system or user level during installation. Then Cygwin will take them automaticaly. If this is not the case, then it is possible to add these variables to System | Environment Variables manually or it is necessary just to execute this file before starting cygwin. For example, it is possible to add the execution of this file directly in cygwin.bat before starting shell.

Alternatively one can convert the commands from vcvars32.bat to the shell used under Cygwin. Under tsch this will be as follows

setenv VSINSTALLDIR "C:\Programme\Microsoft Visual Studio 8"
setenv VCINSTALLDIR "C:\Programme\Microsoft Visual Studio 8\VC"
setenv FrameworkDir "C:\WINDOWS\Microsoft.NET\Framework"
setenv FrameworkVersion v2.0.50727
setenv FrameworkSDKDir "C:\Programme\Microsoft Visual Studio 8\SDK\v2.0"
setenv DevEnvDir "C:\Programme\Microsoft Visual Studio 8\Common7\IDE"
setenv PATH "/cygdrive/c/Programme/Microsoft Visual Studio 8/Common7/IDE:/cygdrive/c/Programme/Microsoft Visual Studio 8/VC/BIN:/cygdrive/c/Programme/Microsoft Visual Studio 8/Common7/Tools:/cygdrive/c/Programme/Microsoft Visual Studio 8/SDK/v2.0/bin:/cygdrive/c/WINDOWS/Microsoft.NET/Framework/v2.0.50727:/cygdrive/c/Programme/Microsoft Visual Studio 8/VC/VCPackages:$PATH"
setenv INCLUDE "C:\Programme\Microsoft Visual Studio 8\VC\INCLUDE;C:\Programme\Microsoft Platform SDK\Include;$INCLUDE"
setenv LIB "C:\Programme\Microsoft Visual Studio 8\VC\LIB;C:\Programme\Microsoft Visual Studio 8\SDK\\v2.0\lib;C:\Programme\Microsoft Platform SDK\Lib;$LIB"
setenv LIBPATH "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727"

Under bash you have to modify these command accordinly. It is possible to add these files to .login or .cshrc or just to save to some file, say ms.conf and then execute

$ source ms.conf

when necessary.

When everything is done correctly, then the command cl should produce an output as below.

$ cl

Microsoft (R) 32-Bit C/C++-Optimierungscompiler Version 14.00.50727.762 für 80x86
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Syntax: cl [ Option... ] Dateiname... [ /link Linkeroption... ]


By default VC++ turns safe iterators on and loose performance:

Numerics: Visual C++ vs. g++
optimization in VC++ Express Edition 2005 Options

Comments are closed.