赞
踩
C/C++
C/C++ Clang Command Adapter
Code Runner
CodeLLDB
Ctrl + Shift + P,找到后点击,则会在工作目录中多出一个 .vscode 目录,进入,会有一个c_cpp_properties.json文件,我们就将要在这里面配置需要的头文件。
然后打开命令行,输入gcc -v -E -x c++ -
将上述得到的信息最下面的那些路径,添加到刚才vscode创建的c_cpp_properties.json中,如下所示,这样#include后面就不会出现红色波浪线了。
{ "configurations": [ { "name": "Mac", "includePath": [ "${workspaceFolder}/**", "/usr/local/include/**", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/**", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/include/**", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/**", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/**", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/**" ], "defines": [], "macFrameworkPath": [], "compilerPath": "/usr/local/bin/gcc-10", "cStandard": "gnu17", "cppStandard": "gnu++14", "intelliSenseMode": "macos-gcc-x64" } ], "version": 4 }
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "lldb", "preLaunchTask": "C/C++: g++ build active file" } ] }
问题描述:VS Code中出现“未定义标识符”,可以右键“转到声明”,但会一直出现红色提醒。
问题原因:VS Code intellisense不能自动找到需要的头文件路径,需要在用户设置中强制intellisense使用Tag Parser,递归方式检索头文件。
解决方式:找到工程对应的settings.json,并复制以下两个语句,在其中配置使用Tag Parser方式。
{
"C_Cpp.intelliSenseEngineFallback": "Disabled", //需要添加的
"C_Cpp.intelliSenseEngine": "Tag Parser", // 需要添加的
}
参考文章:
https://blog.csdn.net/qq_43784626/article/details/111638186
https://www.icode9.com/content-1-790824.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。