在 Cygwin shell 中调用 cl.exe(MSVC 编译器) [英] Invoking cl.exe (MSVC compiler) in Cygwin shell
问题描述
我大量使用 Cygwin(带有 PuTTY shell).但是,在 Cygwin Bash shell 中调用 cl.exe
(即 Visual C++ 编译器工具链)非常棘手.在 Bash shell 中运行 vcvars*.bat
显然不起作用.我尝试将 VC++ 的环境变量迁移到 Cygwin,但没那么容易.
I'm heavily using Cygwin (with PuTTY shell). But, it's quite tricky to invoke cl.exe
(that is, the Visual C++ compiler toolchain) in the Cygwin Bash shell. Running vcvars*.bat
in the Bash shell doesn't work obviously. I tried to migrate VC++'s environment variables to Cygwin, but it's not that easy.
如何在 Cygwin 的 Bash shell 中运行 VC++ 编译器?
How do I run the VC++ compiler in Cygwin's Bash shell?
推荐答案
我通常通过添加
call "%VS80COMNTOOLS%vsvars32.bat" >NUL:
到 c:/cygwin/cygwin.bat.请注意,VS80COMNTOOLS 变量非常有用,因为它为您提供了一种万无一失的 (hm) 方法来定位 vsvars32.bat.
to c:/cygwin/cygwin.bat. Note that the VS80COMNTOOLS variable is extremely useful, since it gives you a foolproof (hm) way of locating vsvars32.bat.
另一种方法是这样,它允许您轻松地在不同的 Studio 版本之间切换:
Another approach is this, which allows you to easily switch between different Studio versions:
function run_with_bat()
{
batfile=$1; shift
tmpfile="$TMP/tmp$$.bat"
echo "@echo off" > $tmpfile
echo "call "%$batfile%vsvars32.bat" >NUL:" >> $tmpfile
echo "bash -c "%*"" >> $tmpfile
cmd /c `cygpath -m "$tmpfile"` "$@"
status=$?
rm -f $tmpfile
return $status
}
function run_vs9()
{
run_with_bat VS90COMNTOOLS "$@"
}
function run_vs8()
{
run_with_bat VS80COMNTOOLS "$@"
}
您现在可以:
$ run_vs8 cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
$ run_vs9 cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
注意编译器版本.
这篇关于在 Cygwin shell 中调用 cl.exe(MSVC 编译器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!