问题
c/c++标准库头文件的路径找不到时,IntelliSense会在头文件下用绿色波浪线(squiggles)进行提示。
解决方法
有两种方式可以解决,一种是通过command+shift+p命令打开:c/c++:edit configuration UI;一种是通过command+shift+p命令打开:c/c++:edit configuration JSON,即c_cpp_properties.json文件。
头文件的选择要跟编译器对应。在mac下我安装了两个编译器,一是通过brew安装的gcc-7,-7是版本号;另一个是安装xcode或系统自带的clang;
用以下命令查看对应编译器的查找路径,好用!
比如用下面的命令分别查看gcc-7的安装路径和头文件查找路径:
which gcc-7
gcc-7 -v -E -x c++ -
将第一条命令的输出结果配置为 compilerPath
将第二条命令的输出结果配置为includePath
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include",
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
因为安装了两个编译器,导致配置失败的原因在于compilerPath和includePath不对应。