vscode 编译代码时 include 报错
-
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"
],