VSCode导入#include <stdio.h>文件时提示以下错误:
#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/wk/c01/main.c) will be provided by the Tag Parser.cannot open source file "stddef.h" (dependency of "stdio.h")
这是由于配置中没有指定依赖路径导致的,在c_cpp_properties.json中includePath的默认配置只有当前目录,需要将系统依赖加入。
在命令行里面输入gcc -v -E -x c++ -
在结果里面找到头文件目录,然后添加到includepath中。
运行结果如下:
使用内建 specs。
COLLECT_GCC=gcc
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
目标:x86_64-redhat-linux
配置为:../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 7.3.1 20180130 (Red Hat 7.3.1-2) (GCC)
COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -E -quiet -v -D_GNU_SOURCE - -mtune=generic -march=x86-64
忽略不存在的目录“/usr/lib/gcc/x86_64-redhat-linux/7/include-fixed”
忽略不存在的目录“/usr/lib/gcc/x86_64-redhat-linux/7/../../../../x86_64-redhat-linux/include”
#include "..." 搜索从这里开始:
#include <...> 搜索从这里开始:
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward
/usr/lib/gcc/x86_64-redhat-linux/7/include
/usr/local/include
/usr/include
搜索列表结束。
将以下路径添加到includePath中
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward
/usr/lib/gcc/x86_64-redhat-linux/7/include
/usr/local/include
/usr/include
配置好的c_cpp_properties.json如下:
{
"configurations": [{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7",
"/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux",
"/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward",
"/usr/lib/gcc/x86_64-redhat-linux/7/include",
"/usr/local/include",
"/usr/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}],
"version": 4
}