安装构建工具后找不到 Visual Studio Code MSVC cl.exe

新手上路,请多包涵

设置 VS Code 后,安装构建工具并在此处完成教程: https ://code.visualstudio.com/docs/cpp/config-msvc

Visual Studio Code 找不到用于编译 C++ 的 cl.exe。

我用硬盘驱动器上的正确路径替换了教程中的路径(cl.exe 在那里)。

 // My Config
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.22.27905/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

// The tutorial build-task
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "msvc build",
            "type": "shell",
            "command": "cl.exe",
            "args": [
                "/EHsc",
                "/Zi",
                "/Fe:",
                "helloworld.exe",
                "helloworld.cpp"
            ],
            "group":  {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal":"always"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

运行构建任务时会显示此错误,尽管 compilerPath 是正确的(cl.exe 在那里)并且 helloworld.cpp 也存在。以管理员身份运行一切都没有帮助。

 cl.exe : The term 'cl.exe' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:1 char:1
+ cl.exe /EHsc /Zi /Fe: helloworld.exe helloworld.cpp
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (cl.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

原文由 Krck 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
1 个回答

‘c_cpp_properties.json’ 文件仅在 C/C++ 扩展中配置 IntelliSense,因此 compilerPath 选项对构建没有帮助。

确保 从 Developer Command Prompt 启动 VS Code 。这将设置必要的环境变量,包括“cl.exe”的位置。

原文由 Callum Watkins 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题