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"
            ],
相关推荐
clint4561 天前
C++进阶(1)——前景提要
c++
夜悊1 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴1 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0012 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾2 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you2 天前
constexpr函数
c++
凡人叶枫2 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫2 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++
小胖xiaopangss2 天前
BRpc使用
c++·rpc
-森屿安年-2 天前
63. 不同路径 II
c++·算法·动态规划