I am trying to convert a header file into a module by compiling the following:
// def.ixx
export module def;
#include <concurrent_unordered_map.h>
import std;
export using dictionary = std::unordered_map<std::string, std::variant<double, std::string, bool, std::vector<double>, int, std::size_t>>;
export using results = std::unordered_map<std::string, std::vector<double>>;
export using pool_results = std::unordered_map<std::string, std::vector<std::vector<std::vector<std::vector<double>>>>>;
export using cache = concurrency::concurrent_unordered_map<std::size_t, results>;
export using pool_cache = std::unordered_map<std::size_t, pool_results>;
I have previously compiled the std
module. I am compiling with cl /std:c++latest /EHsc /nologo /reference "std=std.ifc" def.ixx
and get the following error:
def.ixx
def.ixx(5): warning C5244: '#include <concurrent_unordered_map.h>' in the purview of module 'def' appears erroneous. Consider moving that directive before the module declaration, or replace the textual inclusion with 'import <concurrent_unordered_map.h>;'.
def.ixx(3): note: see module 'def' declaration
LINK : fatal error LNK1561: entry point must be defined
I have tried as it suggests, however, a new error appear. Is it possible to use std
as a module and also use concurrency
/concurrent_unordered_map
?
The correct way to use include with module is to put them in the global module fragment:
// def.ixx
module; // global module fragment
#include <concurrent_unordered_map.h> // don't claim ownership of the declarations
export module def;
import std;
export using dictionary = std::unordered_map<std::string, std::variant<double, std::string, bool, std::vector<double>, int, std::size_t>>;
export using results = std::unordered_map<std::string, std::vector<double>>;
export using pool_results = std::unordered_map<std::string, std::vector<std::vector<std::vector<std::vector<double>>>>>;
export using cache = concurrency::concurrent_unordered_map<std::size_t, results>;
export using pool_cache = std::unordered_map<std::size_t, pool_results>;
Every translation units that needs to include this header will have to re-parse/re-compile the same header, as this is textual inclusion, as opposed to import header.
To instead use header units, you must precompile it first:
cl /nologo /EHsc /std:c++latest /exportHeader path/to/concurrent_unordered_map.h
Then reference it when compiling:
cl /std:c++latest /EHsc /nologo /reference "std=std.ifc" def.ixx /headerUnit concurrent_unordered_map.h=concurrent_unordered_map.h.ifc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With