Invoking cl.exe (MSVC compiler) in Cygwin shell

前端 未结 12 2217
执念已碎
执念已碎 2020-12-04 16:50

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

12条回答
  •  醉梦人生
    2020-12-04 17:34

    I actually used JesperE answer https://stackoverflow.com/a/374411/380247 (that allows you to switch between VS versions) but found a way not to create temporary bat file. So result is much simpler.

    function run_in_vs_env
    {
        eval vssetup="\$$1\\vsvars32.bat"
        cmd /Q /C call "$vssetup" "&&" "${@:2}"
    }
    
    function run_vs11
    {
        run_in_vs_env VS110COMNTOOLS "$@"
    }
    
    function run_vs10
    {
        run_in_vs_env VS100COMNTOOLS "$@"
    }
    

    I suggest to add these lines to your .bash_functions or something similar and export these functions there. This will allow you to use functions in your bash scripts.

    export -f run_in_vs_env
    export -f run_vs11
    export -f run_vs10
    

    Then you should be able to do:

    run_vs11 cl
    

提交回复
热议问题