I am currently trying to use c++ modules in a code that should compile both on Windows (MSVC) and Linux (Clang and/or GCC).
I am currently developping in Visual Studio and used the "Standard Conformance Mode" (/permissive-) to make my code as portable as possible.
However the following code:
import std.core;
int main()
{
std::cout << "Hello, World! haha" << std::endl;
std::vector<int> myVec{4};
std::map<std::string, size_t> myMap;
return 0;
}
Can not compile with the /permissive- flag. I get the following error:
E3223 Cound not find module file "std.core" for import
error C2664: 'int _CrtDbgReport(int,const char *,int,const char *,const char *,...)': cannot convert argument 4 from 'int' to 'const char *'
I tought "std.core" might be a windows-only thing so i tried the following (i saw it in many examples) :
import <iostream>;
import <vector>;
import <map>;
But it results in the following errors:
error C7612: could not find header unit for 'PATH_TO_VS\include\iostream'
error C7612: could not find header unit for 'PATH_TO_VS\include\vector'
error C7612: could not find header unit for 'PATH_TO_VS\include\map'
Note : There are actually files named "iostream", "vector", and "map" in PATH_TO_VS\include.
Therefore i'm wondering what is the standard way of importing c++ modules ? If "import std.core" is the standard way, why doesn't it compile with /permissive- ?
I am using Visual Studio 2019 (Community) and CMake.
Edit:
Sorry i forgot to tell my compiler flags:
/experimental:module
/std:c++latest
/W4
/WX
/permissive-
/MDd
/EHsc
The code compiles without /permissive-, but does not when it is set. I can't figure out why
std.core
isn't a Windows thing. – Aluan Haddadimport<>
syntax is part of C++20 for the standard library. (User-written modules can be used viaimport foo;
.) – Davis Herring