【问题标题】:Code Runner using MSVC create a too long stringCode Runner 使用 MSVC 创建过长的字符串
【发布时间】:2019-11-06 14:50:54
【问题描述】:

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

{
    "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!所以经过几次运行后,总路径变得太长了:

"Input line is too long" error in BAT File

重启控制台清除,但运行几次后又掉了。

看来我需要想办法只使用一次vcvars64.bat,但我不知道怎么做!

【问题讨论】:

  • 首先在命令提示符中运行 vsvars64.bat,然后从该命令提示符运行 coderunner(Visual Studio 添加了一个快捷方式来执行此操作:Visual Studio 2019(或类似版本)的命令提示符)

标签: c++ visual-c++ visual-studio-code vscode-code-runner


【解决方案1】:


这是我的setting.json

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

它按预期工作。

【讨论】:

  • 感谢您的回复!这是工作,但我需要第一次手动使用vcvars64.bat。如何自动使用它?在我的示例中,我在 code-runner.executorMap 中使用了 vcvars64.bat,这是一个错误问题。
  • 不知道它在 cmd 中不工作,但在 powerShell 中工作正常。
【解决方案2】:

在 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",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-20
    • 2020-12-11
    • 1970-01-01
    • 2021-09-14
    • 2023-01-03
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    相关资源
    最近更新 更多