I would like to use the C 20 Modules in VS 2022. Unfortunately, I cannot use intellisence, even on a very simple test. I put options as "C latest", "Modules", Advanced>>"Compile as C module code".
Unfortunately, there are squiggles at the file beginning, and no intellisence, and no identifiers highlighting. Also, we cannot import std;
anymore (nor std.core).
//Test of modules.
#define MODULES
#ifdef MODULES
import module1;
#else
#include <iostream>
#include <vector>
#include <format>
#endif
std::vector<std::string> vec{"Some", " sentence", " to", " print !"};
int main()
{
std::cout << std::format("Hello World!\n");
for (auto & str : vec) {
std::cout << std::format("{}", str);
}
return 0;
}
The file module1.ixx:
export module module1;
export import <iostream>;
export import <format>;
export import <string>;
export import <vector>;
export import <deque>;
export import <chrono>;
Can someone tell me what I am missing ?
VS and intellisence work perfectly with the #include
without any problem.
CodePudding user response:
Intellisence module support is still experimental.
I tested your code in Visual Studio 2022 Version 17.4.3 and there was no issues.
However, Visual Studio 2022 Version 17.5.0 Preview 2.0 shows a couple of squiggles.
ISO committee(C 23) voted for import std;
and import std.compat;
.
To use import std;
in preview version(17.5.0) you need to add std.ixx file. In my machine, the file is located in C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32124\modules.
Add the file from Solution Explorer(Add -> existing Item...).
Please, refer to this site for more information. https://learn.microsoft.com/en-us/cpp/cpp/tutorial-import-stl-named-module?view=msvc-170