c_cpp_properties.json的includePath配置后,按F12可以查看定义。
c_cpp_properties.json文件内容:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\Users\\sometwo\\Downloads\\ogldev-master\\Include\\**",
"C:/Users/sometwo/Downloads/ogldev-master/Include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\tool\\Dev-Cpp_6.3_TDM-GCC_9.2_Portable\\TDM-GCC-64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
但如果tasks.json未配置头文件路径,还是会报错:
Starting build...
D:\tool\Dev-Cpp_6.3_TDM-GCC_9.2_Portable\TDM-GCC-64\bin\g++.exe -g C:\Users\sometwo\Downloads\ogldev-master\tutorial02\tutorial02.cpp -lglew32 -lfreeglut -lopengl32 -o C:\Users\sometwo\Downloads\ogldev-master\tutorial02\tutorial02.exe
C:\Users\sometwo\Downloads\ogldev-master\tutorial02\tutorial02.cpp:24:10: fatal error: ogldev_math_3d.h: No such file or directory
24 | #include "ogldev_math_3d.h"
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Build finished with error(s).
The terminal process failed to launch (exit code: -1).
修改tasks.json文件,增加一行
"-I\"C:\\Users\\sometwo\\Downloads\\ogldev-master\\Include\"",
修改后的文件为:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\tool\\Dev-Cpp_6.3_TDM-GCC_9.2_Portable\\TDM-GCC-64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-lglew32",
"-lfreeglut",
"-lopengl32",
"-I\"C:\\Users\\sometwo\\Downloads\\ogldev-master\\Include\"",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
搜索资料,Windows也可以通过配置环境变量
D:\xxx\c\opengl>echo %C_INCLUDE_PATH%
%C_INCLUDE_PATH%
D:\xxx\c\opengl>echo %CPLUS_INCLUDE_PATH%
%CPLUS_INCLUDE_PATH%
以上表示未配置。未验证。