Visual Studio Code的C语言头文件包含问题

Linux系统,在配置VSCode的C语言开发环境时,会有头文件包含问题:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/home/yty/Project/C/demo.c).

这是因为C语言配置文件c_cpp_properties.json中未包含依赖路径,解决方法:

  • 找到本地头文件目录
    打开terminal,输入 gcc -v -E -x c++ -,结果如下:

    gcc 版本 9.1.0 (GCC) 
    COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=generic' '-march=x86-64'
    /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/cc1plus -E -quiet -v -D_GNU_SOURCE - -mtune=generic -march=x86-64
    忽略不存在的目录“/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/include”
    #include "..." 搜索从这里开始:
    #include <...> 搜索从这里开始:
    /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0
    /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/x86_64-pc-linux-gnu
    /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/backward
    /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/include
    /usr/local/include
    /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/include-fixed
    /usr/include
    
  • 添加到配置文件
    找到c_cpp_properties.json文件中的includePath,添加成如下

    "includePath": [
                "${workspaceFolder}/**",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/x86_64-pc-linux-gnu",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/backward",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/include",
                "/usr/local/include",
                "/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/include-fixed",
                "/usr/include"
            ]
    

最后保存即可

参考:https://www.jianshu.com/p/a2a4bc46f30e

你可能感兴趣的:(Visual Studio Code的C语言头文件包含问题)