0

我在 Windows 上使用 CodeRunner for VSCode,所以我需要将 g++ 更改为 MSVC(Visual C++ 编译器)。所以我settings.json为coderunner配置:

{
    "window.zoomLevel": 0,
    "code-runner.runInTerminal": true,
    "terminal.integrated.shell.windows": "cmd.exe",
    "code-runner.executorMap": {
        "cpp": "vcvars64.bat && cl.exe $fileName && del $fileNameWithoutExt.obj && cls && $fileNameWithoutExt.exe",
    },
    "files.autoSave": "afterDelay"
}

如您所见,我将 vcvars64.bat 的路径添加到系统 PATH 中。它可以工作,但是经过几次运行后,我得到下一个错误:

输入行太长。

搜索了一下,发现是因为CodeRunner每次都运行vcvars64.bat!所以经过几次运行后,总路径变得太长:

BAT 文件中的“输入行太长”错误

重新启动控制台清除它,但几次运行后再次下降。

看起来我需要找到一些vcvars64.bat只使用一次的方法,但我不知道怎么做!

4

2 回答 2

1

在 vs-code 中将默认 shell更改为PowerShell

"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",

然后将其添加setting.json文件中:

对于 PowerShell

"cpp": "cd $dir ; vcvars64.bat ;  cl /EHsc $fileName ; ./$fileNameWithoutExt.exe",
于 2020-02-22T18:08:33.020 回答
1


这是我的setting.json

"code-runner.executorMap": {
    "cpp": "cd $dir && cl /EHsc $fileName && cls && $dir$fileNameWithoutExt.exe && del 
  $dir$fileNameWithoutExt.obj $dir$fileNameWithoutExt.exe",
},

按预期工作

于 2020-02-14T21:39:52.533 回答