The default includePath in freshly generated c_cpp_properties.json file for macOS and Linux targets are /usr/include and /usr/local/include. But these are usually insufficient, especially on macOS with Xcode installed. For example, on my macOS, the includePath for standard libraries and OS SDK resides in
[
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include",
"/usr/include",
"/usr/local/include"
]
These default include settings could be parsed out of the output of c++ -E -x c++ - -v < /dev/null. Visual Studio Code should do this automatically.
The default includePath on Mac is not supposed to be /usr/include and /usr/local/include. It is supposed to have the XCode paths. What OS are you generating the c_cpp_properties.json on? If you on a non-Mac OS you won't get the Mac paths. It's possible the code we use to generate those paths is hitting some error with your installation setup. I'm seeing the 1st 3 XCode paths generated on my Mac, but not the 4th MacOSX SDK one, so it seems we should add that one too.
I'm on macOS Sierra. OK, it seems that the last update to cpptools has added the three Xcode paths. But still, the SDK one is not automatically added, so vscode cannot find c standard headers such as stddef.h.
Okay, thanks for letting us know about this problem. We'll try to add that in a future update.
stddef.h should be in
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include
Adding the MacOSX SDK path should have no effect on where stddef.h is being pulled from. I don't see an #include_next in there. However, I think parsing the default include path from clang's output is a good suggestion and is something we can do in a future update.
In Ubuntu 16.04.3 LTS (gcc: Ubuntu 5.4.0-6ubuntu1~16.04.4) stddef.h is also not found. It is at path /usr/lib/gcc/x86_64-linux-gnu/5/include/, which was not by default in c_cpp_properties.json.
Same issue here on Arch Linux, yet the path for stddef.h is /usr/include/linux/stddef.h.
@KireinaHoro Usually there are multiple copies of different stddef.h files laying around, /usr/include/linux in particular contains the kernel headers. You should rather use the compiler's library header, you can find it with find / -name stddef.h 2>/dev/null.
@fo-fo
Well, I get /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/stddef.h.
@KireinaHoro, the /usr/lib/gcc/... path you listed is most likely the one you want.
This should be fixed in 0.14.3
@bobbrow can you clarify whether the c_cpp_properties.json files for existing projects need to be manually fixed up or whether that will happen automatically?
Unfortunately, it will not be fixed up automatically for existing projects since we do not currently have separate properties for system include paths vs. project include paths and don't want to take the risk of removing something that somebody manually tuned previously.
If you delete or rename your c_cpp_properties.json file and generate a new one, the new one will query the defaults from clang or gcc and then you can copy back in the remaining project paths from the old json file.
Not sure what the expectations are for the current build, but on vscode 1.21.1 & Ubuntu 16.04 the c_cpp_properties.json is wrong. Would be nice if the default had the correct paths.
@weswitt, what defaults are you getting?
Most helpful comment
Unfortunately, it will not be fixed up automatically for existing projects since we do not currently have separate properties for system include paths vs. project include paths and don't want to take the risk of removing something that somebody manually tuned previously.
If you delete or rename your c_cpp_properties.json file and generate a new one, the new one will query the defaults from clang or gcc and then you can copy back in the remaining project paths from the old json file.