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"
            ],
相关推荐
煤球王子23 分钟前
学而时习之:C++中的文件处理2
c++
fakerth1 小时前
【OpenHarmony】设计模式模块详解
c++·单例模式·设计模式·openharmony
biter down1 小时前
C++ 解决海量数据 TopK 问题:小根堆高效解法
c++·算法
程芯带你刷C语言简单算法题1 小时前
Day28~实现strlen、strcpy、strncpy、strcat、strncat
c语言·c++·算法·c
一个不知名程序员www2 小时前
算法学习入门--- 树(C++)
c++·算法
Simon席玉2 小时前
C++的命名重整
开发语言·c++·华为·harmonyos·arkts
仰泳的熊猫2 小时前
1148 Werewolf - Simple Version
数据结构·c++·算法·pat考试
十五年专注C++开发2 小时前
同一线程有两个boost::asio::io_context可以吗?
c++·boost·asio·异步编程·io_context
面壁的熊猫3 小时前
cursor+cline+MCP(论文agent)
vscode·agent·cursor·mcp
xlq223223 小时前
26 avl树(下)
c++