在Cygwin shell中调用cl.exe(MSVC编译器) [英] Invoking cl.exe (MSVC compiler) in Cygwin shell

查看:1164
本文介绍了在Cygwin shell中调用cl.exe(MSVC编译器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大量使用Cygwin(使用 PuTTY shell)。但是,在Cygwin Bash shell中调用 cl.exe (即Visual C ++编译器工具链)非常棘手。在Bash shell中运行 vcvars * .bat 不会很明显。我尝试将VC ++的环境变量迁移到Cygwin,但是这并不容易。



如何在Cygwin的Bash shell中运行VC ++编译器?

$ b $我通常通过添加

 来解决这个问题。 %VS80COMNTOOLS%vsvars32.bat> NUL:

到c:/cygwin/cygwin.bat。请注意,VS80COMNTOOLS变量是非常有用的,因为它给你一个万无一失(vm)的方式来定位vsvars32.bat。



另一种方法是这样,在不同的Studio版本之间切换:

  function run_with_bat()
{
batfile = $ 1; shift
tmpfile =$ TMP / tmp $$。bat
echo@echo off> $ tmpfile
echocall \%$ batfile%vsvars32.bat\> NUL:>> $ tmpfile
echobash -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位C / C ++优化编译器版本14.00.50727.762(对于80x86)
版权所有(C)Microsoft Corporation。版权所有。

用法:cl [option ...] filename ... [/ link linkoption ...]
$ run_vs9 cl
Microsoft(R)32位C / C ++优化编译器版本15.00.21022.08 for 80x86
版权所有(C)Microsoft Corporation。版权所有。

用法:cl [option ...] filename ... [/ link linkoption ...]

注意编译器版本。


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.

How do I run the VC++ compiler in Cygwin's Bash shell?

解决方案

I usually solve this by adding

call "%VS80COMNTOOLS%vsvars32.bat" >NUL:

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.

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 "$@"
}

You can now do:

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

Note the compiler version.

这篇关于在Cygwin shell中调用cl.exe(MSVC编译器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆