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... ]

Discussion

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

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


Comments

2 responses to “Using Microsoft Visual C under Gygwin”

Comments are now closed
  1. Hojat Badnava says:

    Hi
    I did all step described and cygwin env print is:
    $ printenv
    HOMEPATH=\Users\hojat
    MANPATH=/usr/local/man:/usr/share/man:/usr/man::/usr/ssl/man
    APPDATA=C:\Users\hojat\AppData\Roaming
    HOSTNAME=hojat-PC
    INTEL_LICENSE_FILE=C:\Program Files\Common Files\Intel\Licenses
    SHELL=/bin/bash
    TERM=xterm
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel
    WINDIR=C:\Windows
    VS80COMNTOOLS=C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\
    PUBLIC=C:\Users\Public
    OLDPWD=/cygdrive/c/Users/hojat/Desktop
    USERDOMAIN=hojat-PC
    OS=Windows_NT
    ALLUSERSPROFILE=C:\ProgramData
    windows_tracing_flags=3
    USER=hojat
    windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
    !::=::\
    TEMP=/tmp
    temp=C:\Users\hojat\AppData\Local\Temp
    VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\
    COMMONPROGRAMFILES=C:\Program Files\Common Files
    tmp=C:\Users\hojat\AppData\Local\Temp
    IFORT_COMPILER11=C:\Program Files\Intel\Compiler\11.072\fortran\
    MSMPI_INC=C:\Program Files\Microsoft HPC Pack 2008 R2\Inc\
    MSMPI_LIB32=C:\Program Files\Microsoft HPC Pack 2008 R2\Lib\i386\
    USERNAME=hojat
    PROCESSOR_LEVEL=6
    PATH=/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/Intel/Compiler/11.0/072/fortran/lib/ia32:/cygdrive/c/Program Files/Microsoft HPC Pack 2008 R2/Bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Microsoft SQL Server/90/Tools/binn:/cygdrive/c/SIMULIA/Abaqus/Commands:/cygdrive/c/Program Files/MATLAB/R2010a/runtime/win32:/cygdrive/c/Program Files/MATLAB/R2010a/bin:/cygdrive/c/Program Files/CMake 2.8/bin:/usr/lib/lapack
    PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
    FP_NO_HOST_CHECK=NO
    PWD=/home/hojat
    SYSTEMDRIVE=C:
    LANG=en_US.UTF-8
    USERPROFILE=C:\Users\hojat
    TZ=Asia/Tehran
    PS1=\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$
    LOGONSERVER=\\HOJAT-PC
    PROCESSOR_ARCHITECTURE=x86
    LOCALAPPDATA=C:\Users\hojat\AppData\Local
    LM_LICENSE_FILE=27000@hojat-PC
    ProgramData=C:\ProgramData
    SHLVL=1
    HOME=/home/hojat
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    HOMEDRIVE=C:
    MSMPI_LIB64=C:\Program Files\Microsoft HPC Pack 2008 R2\Lib\amd64\
    COMSPEC=C:\Windows\system32\cmd.exe
    TMP=/tmp
    SYSTEMROOT=C:\Windows
    MPI_ROOT=C:\Program Files\Hewlett-Packard\HP-MPI
    PRINTER=PDFCreator
    PROCESSOR_REVISION=1706
    INFOPATH=/usr/local/info:/usr/share/info:/usr/info:
    PROGRAMFILES=C:\Program Files
    NUMBER_OF_PROCESSORS=2
    SESSIONNAME=Console
    COMPUTERNAME=HOJAT-PC
    _=/usr/bin/printenv

    But when I type cl command:
    -bash: cl: command not found

    Why?

  2. You need to check your PATH. The message says that cl is not on the path.