Geoffrey Hoffmann
Geoffrey Hoffmann

Reputation: 155

How to get Modules to work in VS2019 16.8?

I'm trying to convert my program to modules. I'm using MSVS 19 Community Edition version 16.8 (also tried with MSVS19CE Version 16.9.01 Preview)

Each .ixx IDF I write compiles fine when compiled indiviually, (with "import"'s and its usage commented out),

Build started...
1>------ Build started: Project: myCare, Configuration: Debug x64 ------
1>Scanning sources for module dependencies...
1>Compiling...
1>DB.ixx
1>Compiling...
1>HS.ixx
1>pch.cpp
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

But when I introduce the commented out imports, suddenly VS can't find the modules it just previously compiled beautifully.

Build started...
1>------ Build started: Project: myCare, Configuration: Debug x64 ------
1>Scanning sources for module dependencies...
1>Compiling...
1>HS.ixx             <<<<-----  Compiled without errors
1>Compiling...
...
1>ComplexComboBox.ixx
1>D:\Dev\myCare\Modules\ComplexComboBox.ixx(289,1): error C2230: could not find module 'HS'
1>D:\Dev\myCare\Modules\ComplexComboBox.ixx(289,1): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\CL.exe'
1>    Please choose the Technical Support command on the Visual C++
1>    Help menu, or open the Technical Support help file for more information
1>Done building project "myCare.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
error C2230: could not find module 'HS'
error C2230: could not find module 'Aui'
error C2230: could not find module 'Ctrl.ListCtrl'

Any hints? Every module has the structure like this (and has the file extension .ixx)

module;

#include "Defines.h"
#include <any>
#include <bitset>

...

export module HS;

namespace HS
{
    export enum class Comms { None = 0, Port = 1, Timeout = 2, Authority = 3, Security = 4 };
    
    export auto CommsAuthority(const AuthorityType newValue)->void;
    export auto CommsAuthority(void)->AuthorityType;
    
    (Not everything in here is exported)
    ...
}

module :private;

auto HS::CommsAuthority(const AuthorityType newValue)->void
{
    ...
}
auto HS::CommsAuthority(void)->AuthorityType
{
    ...
}

...

Upvotes: 0

Views: 1414

Answers (1)

ThirdWiseMonkey
ThirdWiseMonkey

Reputation: 239

This seems to be a bug with the way visual studio currently handles modules imported by other modules. Essentially when each module compiles it creates a <module_file_name>.ixx.ifc file. This is detected perfectly fine when the module is imported into a cpp file but not when importing to a module. removing the .ixx from the filename will import correctly whether importing to another module or a cpp file though.

I solved this in 1 of my own projects through the project properties(the required options are only available in the preview version of visual studio at the moment though).

So you first need to set Module File name to $(IntDir)%(Filename).ifc in C/C++->Output Files

Then set Additional BMI Directories to $(IntDir) in C/C++->General.

Visual studio puts all the intermediate module stuff in the intermediate directory by default but if you'd rather have all your intermediate module things in a separate folder you can set Module Dependencies File in C/C++->Advanced to wherever you want and then update the $(IntDir) bits above to the new location.

Upvotes: 2

Related Questions