How to import a C++20 module from another directory?

Viewed 955

I am trying to use the module feature from C++20 since MSVC and GCC11 kinda supports it now. With header files we could put relative/full path of header to include them. But how do we import modules which are in some other folders than the source? Also is there an option in Visual Studio to include the import path or something?

1 Answers

From A Tour of C++ Modules in Visual Studio (thanks to JHBonarius):

Your code can consume modules in the same project or any referenced ones automatically (using project-to-project references to static library projects).

It is also possible to reference modules that exist on disk, instead of ones belonging to another project in the solution. Care needs to be taken here, however, because modules are compiled, binary files. You must make sure they are compatible with the way you are building your projects.

You can tell Visual Studio to look for modules on disk by editing the Additional Module Dependencies property:

Configuration Properties >> C++ >> General >> Additional Module Dependencies

Related