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"
            ],
相关推荐
Je1lyfish8 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
Brilliantwxx8 小时前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
kafei_*9 小时前
VScode 添加 UV虚拟环境方法
vscode·python·uv
叼烟扛炮9 小时前
C++第三讲:类和对象(中)
开发语言·c++·类和对象
KuaCpp9 小时前
C++新特性学习
c++·学习
墨染千千秋10 小时前
C/C++ Keywords
c语言·c++
ximu_polaris10 小时前
设计模式(C++)-行为型模式-中介者模式
c++·设计模式·中介者模式
CSCN新手听安11 小时前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
tumu_C12 小时前
用std::function减缓C++模板代码膨胀和编译压力的一个场景
开发语言·c++
Hical6112 小时前
C++17 实战心得:那些真正改变我写代码方式的特性
c++