For example I have following toy files:
mod.hpp
#include <iostream>
use.cpp
import "mod.hpp";
int main() {
std::cout << "Hello, World!" << std::endl;
}
But if you compile it like cl use.cpp /std:c++latest
then I get error
error C7612: could not find header unit for 'mod.hpp'
How do I create/use header units in MSVC?
NOTE: I'm making cross-platform/cross-compiler projects right now. It means that I want same sources to be able to compile in MSVC/CLang/GCC on both Windows and Linux. For me there is no point to make MSVC-specific extensions .ixx/.cppm, thats why I used .hpp/.cpp in my case. More then that I'm not making .vcxproj/.sln files at all, I'm only considered about low-level command line invocation for compiling in MSVC.
This question was made by me just to share my answer with ready-made solution.