想在VS Code中编译一个简单的C++ "Hello world"代码如下

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

 

创建一个tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hellow.cpp",
            "type": "shell",
            "command": "cl",
            "args": [
                "/EHsc",
                "${file}",
                "/Fe:${fileDirname}\\Bin\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": ["$msCompile"],
            "detail": "Generated task by VS Code."
        }
    ]
}

使用VS Code的快捷键 Ctrl + Shift + B, 提示找不到<iostream>的包含路径(编译错误 C1034: <iostream>: 不包括路径集),网上找到解决方法,

 

在Windows的系统环境变量中,新建INCLUDE环境变量,包含路径如下:

  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include;

  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt;

 

然后还需新建LIB环境变量(解决报错:  LNK1104: 无法打开文件“uuid.lib” ),包含路径如下:

  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib;

  C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x86;

  C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;

 

上述路径设置完成。关闭VS Code,再重新打开,

然后使用快捷键 Ctrl + Shift + B,

进行编译生成exe文件成功。

 

 

 

 

 

 

 


 

posted on 2025-03-07 18:27  zdleek  阅读(67)  评论(1)    收藏  举报