vscode 编译c++代码问题

vscode 编译代码时 include 报错

  1. vscode 编译代码时 include 报错,目标代码有 include 自己写的头文件,报错找不到对应的头文件

    • Executing task: C/C++: g++.exe build active file

    Starting build...
    cmd /c chcp 65001>nul && C:\msys64\ucrt64\bin\g++.exe -fdiagnostics-color=always -g C:\Users\0000\3_projects\learn_c++\base-01-helloworld\gaojishuju.cpp -o C:\Users\0000\3_projects\learn_c++\base-01-helloworld\gaojishuju.exe
    C:\Users\0000\3_projects\learn_c++\base-01-helloworld\gaojishuju.cpp:2:10: fatal error: base.h: No such file or directory
    2 | #include <base.h>
    | ^~~~~~~~
    compilation terminated.

    Build finished with error(s).

解决方法:

.vscode/tasks.json 中配置 g++命令中添加如下相关参数,让编译时 include 的目录增加配置中的路径

json 复制代码
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
+                 "-I",
+                 "${fileDirname}\\base",
+                 "-I",
+                 "${fileDirname}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
相关推荐
三天不学习1 小时前
Cursor vs Trae vs VSCode:2025终极IDE横评,谁才是开发者的效率之选?
ide·vscode·编辑器
程序员zgh2 小时前
Linux系统常用命令集合
linux·运维·服务器·c语言·开发语言·c++
獭.獭.3 小时前
C++ -- STL【unordered_set与unordered_map的实现】
开发语言·c++·unordered_map·unordered_set
qq_433554543 小时前
C++数位DP
c++·算法·图论
似水এ᭄往昔3 小时前
【C++】--AVL树的认识和实现
开发语言·数据结构·c++·算法·stl
程序员zgh3 小时前
常用通信协议介绍(CAN、RS232、RS485、IIC、SPI、TCP/IP)
c语言·网络·c++
暗然而日章4 小时前
C++基础:Stanford CS106L学习笔记 8 继承
c++·笔记·学习
一苓二肆4 小时前
代码常用工具使用
git·vscode·docker·github·vim
有点。4 小时前
C++ ⼀级 2023 年06 ⽉
开发语言·c++
charlie1145141914 小时前
编写INI Parser 测试完整指南 - 从零开始
开发语言·c++·笔记·学习·算法·单元测试·测试