D:\MyLearn\vsCode下有:
-> include
-->demo.hh
-> source
--> main.cpp
-->demo.cpp
单独编译main.cpp 不加入demo.hh时能正常编译过;
扩展自己的文件时,找不到路径?
很明显时头文件路径没找到, 并且编译时还需将demo.cpp一起带上;
接下来一起看看三个配置文件:
F5选择gdb和g++相关;
只改动了"externalConsole": true,其余没动;
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,//表示打开终端
"MIMode": "gdb",
"miDebuggerPath": "D:\\InstallPath\\vsCode\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
ctrl + shift + p即可生成;选择c/c++ edit UI这个
刚开始尝试在 includePath 中添加,结果均不行; 此文件没改动;
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\InstallPath\\vsCode\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
在args参数中 -I指定头文件路径, 若是有链接开源库需要-L?(没测试)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\InstallPath\\vsCode\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-I${fileDirname}\\..\\include",//添加
"-g",
//"${file}", 屏蔽
"D:\\MyLearn\\vsCode\\source\\*.cpp", //添加
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
重新编译即可;
调试时具体可根据打印分析自己的路径是否正确:
其实缩短看就是: g++ *.h -g *cpp -o xxx.exe
-g 表示为了gdb调试用;
-o 表示将生成的执行程序改名为其他