I'm trying to dabble with the c 20 modules feature and would like to import the standard library headers as modules. Currently I have
import <iostream>;
int main()
{
std::cout << "hello world!" << std::endl;
return 0;
}
and I run the commands
g -11 -fmodules-ts -std=c 20 -xc -system-header iostream
g -11 -fmodules-ts -std=c 20 -o program main.cpp
This gives a perfectly functioning hello world program
and a module file at gcm.cache/usr/include/c /11/iostream.gcm
. But vscode complains:
"iostream" is not an importable header
My c_cpp_properties.json
file is
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g -11",
"cStandard": "c17",
"intelliSenseMode": "linux-clang-x64",
"cppStandard": "c 20"
}
],
"version": 4
}
Possible solutions that I don't know how to implement:
- A way to tell vscode where this
iostream.gcm
file is - An alternative way of doing this where the
iostream.gcm
object ends up somewhere vscode already knows
CodePudding user response:
This is the known IntelliSense issue.
When importing C 20 modules or header units in C source:
- You may not see IntelliSense completions or colorization.
- You may see red squiggles that don’t match the compiler.
Status (as of June 2022)
Workaround
#if __INTELLISENSE__
#include <iostream>
#else
import <iostream>;
#endif