Why do I have problems when trying to import a header unit?
I used VS Developer PowerShell to create a header unit file from a header file.
cl /std:c++20 /exportHeader /headerName:quote HeadersBase.h
Not sure if that was the right thing to do.
Then I created an empty project to see if I can import the header unit successfully.
// ModulesBase.ixx
export module ModulesBase; // command-line error: no mapping specified for C:/Exports/HeadersBase.h.ifc
import "HeadersBase.h"
using namespace std;
export void MyFunc() {}
In the properties of the Modulebase file, I used these in the command-line
/std:c++20 /headerUnit C:\Exports\HeadersBase.h=C:\Exports\HeadersBase.h.ifc /headerUnit:quote HeadersBase.h=C:\Exports\HeadersBase.h.ifc
When I build, I get errors
E3343 ommand-line error: no mapping specified for Test C:\Projects\Test\Test\ModulesBase.ixx 1 Warning C5210 'C:\Exports\HeadersBase.h.ifc' is not a valid header unit reference; ignoring Test C:\Projects\Test\Test\ModulesBase.ixx 1 Error C1083 Cannot open header unit file: 'HeadersBase.h': No such file or directory Test C:\Projects\Test\Test\ModulesBase.ixx 8 Warning MSB8074 Cannot read Module Dependencies file x64\Debug\ModulesBase.ixx.module.json: Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''. The build order might be incorrect. Test C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets 486 Error C1190 System::Object not found, missing /clr option or missing import of standard assemblies? Test C:\Projects\Test\Test\ModulesBase.ixx 3
Windows
C++
-
Minxin Yu 12,351 Reputation points • Microsoft Vendor
2024-12-31T06:53:10.83+00:00 I cannot reproduce the problem. The error message you provided did not occur.
Build project successfully. -
Darran Rowe 1,321 Reputation points
2024-12-31T19:49:38.39+00:00 If the command line stated is what was given, then there is potentially a massive difference in the command line and environment.
As I stated in my previous set of replies, the Windows headers are not well behaved. This means that macros will make a massive difference.
Now, as mentioned, the developer powershell was used to build. The big issue here is that the developer powershell defaults to the x86 compiler.
As I also previously stated, the Windows headers are two APIs in one. The Windows 32 bit API and the Windows 64 bit API. The x86 compiler defines the
_M_IX86
macro automatically, and this is used in Windows.h to automatically tell the headers that it is in the Windows 32 bit API mode, and anything platform specific must be defined for x86.//Taken from Windows.h version 26100 line 106 #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_IX86) #define _X86_ #if !defined(_CHPE_X86_ARM64_) && defined(_M_HYBRID) #define _CHPE_X86_ARM64_ #endif #endif
There are also large blocks in the headers, especially winnt.h, that are conditionally compiler and protected by blocks based on the platform.
Now, the error message states
x64\Debug\ModulesBase.ixx.module.json
In other words, a header unit or module compiled targetting the 32 bit x86 release environment is being used in a 64 bit AMD64 debug build. THIS IS BAD!!!!!
I don't use bold and caps lightly here. Very basic definitions are completely different between the two different APIs. This means that in a 64 bit application, the 32 bit definitions will cause crashes due to pointer truncation and are very hard to diagnose.
Header units and modules should be thought of as precompiled headers and not as include files. The definitions are decided on when the header unit is compiled and not when the application is compiled. This means that when you use a badly behaving header file in a header unit, IT MUST MATCH THE PLATFORM THAT YOU WANT TO USE IT FOR.
I also apologise if the emphasis feels agressive.
Now, instead of writing a lot of what went wrong, here is really what should be done.
First, make sure that the compiler that is used matches the intended environment. So, if the application is built targetting x64, make sure that the header unit is built using the x64 compiler. Secondly, match as many of the command line options as possible from the target project. Command line options that name output files, like /Fo and /Fd don't need to match, but important ones like /O2 and /EHsc really should.
This means that there will potentially be several ifc files, one for each platform:configuration pairs. This is annoying but expected.
-
Minxin Yu 12,351 Reputation points • Microsoft Vendor
2025-01-02T07:15:49.88+00:00 Hope you've been well. Any updates about this issue?
-
CDev-8220 220 Reputation points
2025-01-08T20:58:11.2066667+00:00 Sorry for the delay.
First, make sure that the compiler that is used matches the intended environment. So, if the application is built targetting x64, make sure that the header unit is built using the x64 compiler.
Yes, I am using x64 Native Tool Command Prompt, and in Visual Studio, the architecture is 64 bit.
Secondly, match as many of the command line options as possible from the target project. Command line options that name output files, like /Fo and /Fd don't need to match, but important ones like /O2 and /EHsc really should.
Yes, I realize I was getting compatibility issues, and I fixed those.
cl /W4 /EHsc /std:c++20 /O2 /GA /MD /fp:precise /sdl...
When I work on a project from the command-line, I am able to create the header unit (HeadersBase.h.ifc), and the module file (ModuleBase.ixx.ifc), which imports the header unit -
import "HeadersBase.h";
I can then run this command :
cl ... /headerUnit:quote HeadersBase.h=HeadersBase.h.ifc /reference ModuleBase=ModuleBase.ixx.ifc TestModules.cpp
The
import "HeadersBase.h";
seems to work, butimport ModuleBase;
does not work.The program also does not run.
When I create a project in Visual Studio, and try importing either the header unit, or the module, I am still getting these errors:
Error (active) E3343 command-line error: no mapping specified for Test Warning C5210 'HeadersBase.h.ifc' is not a valid header unit reference; ignoring
However, these are the only errors at the moment.
This means that there will potentially be several ifc files, one for each platform:configuration pairs. This is annoying but expected.
I only get .ifc and .ifcast.
-
Minxin Yu 12,351 Reputation points • Microsoft Vendor
2025-01-09T03:12:29.8933333+00:00 Is the project in release mode?
-
CDev-8220 220 Reputation points
2025-01-09T09:04:02.16+00:00 Yes, but I get the same error in both Release and Debug mode.
-
Minxin Yu 12,351 Reputation points • Microsoft Vendor
2025-01-10T02:39:17.9533333+00:00 Try removing additional cl commands.
Use x64 cl to build commands and set project in debug mode.
cl /std:c++20 /exportHeader /headerName:quote HeadersBase.h
/std:c++20 /headerUnit C:\Exports\HeadersBase.h=C:\Exports\HeadersBase.h.ifc /headerUnit:quote HeadersBase.h=C:\Exports\HeadersBase.h.ifc
-
Minxin Yu 12,351 Reputation points • Microsoft Vendor
2025-01-10T03:16:43.14+00:00 In addition,
import "HeadersBase.h"
missing;
.
There is spelling error:import ModuleBase;
ModulesBase. -
CDev-8220 220 Reputation points
2025-01-11T00:22:04.7166667+00:00 For Debug mode
Error (active) E3343 command-line error: no mapping specified for Test Warning C5210 '...\HeadersBase.h.ifc' is not a valid header unit reference; ignoring Test Warning C5050 Possible incompatible environment while importing module '': _DEBUG is defined in current command line and not in module command line Test
Command-line for the project looks like this:
/JMC /reference "C:...\Debug\ModuleBase.ixx.ifc" /permissive- /ifcOutput "x64\Debug" /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"x64\Debug\vc143.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_WINDOWS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /Fa"x64\Debug" /EHsc /nologo /Fo"x64\Debug" /Fp"x64\Debug\Test.pch" /diagnostics:column /headerUnit "C:...\Debug\HeadersBase.h.ifc"
For Release mode
Error (active) E3343 command-line error: no mapping specified for Test Warning C5210 '...\HeadersBase.h.ifc' is not a valid header unit reference; ignoring Test Error C1004 unexpected end-of-file found Test Warning C5210 '...\HeadersBase.h.ifc' is not a valid header unit reference; ignoring Test
Command-line for the project looks like this:
/reference "C:...\Release\ModuleBase.ixx.ifc" /permissive- /ifcOutput "x64\Release" /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc143.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "_WINDOWS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /std:c++20 /FC /Fa"x64\Release" /EHsc /nologo /Fo"x64\Release" /Fp"x64\Release\Test.pch" /diagnostics:column /headerUnit "C:...\Release\HeadersBase.h.ifc"
The only switch I am using, which is different, is
/GA
optimize for Windows Application, but this should not cause a problem, should it?Removing any of the others causes incompatibility issues, as the environment is different.
I think the problem might be solved, if we figure out why I am getting the error :
no mapping specified for file.
Do you know what is the reason for this error?
-
-
CDev-8220 220 Reputation points
2025-01-11T13:50:44.6733333+00:00 This is getting really stressful.
After creating an ifcMap file:
# Using literal strings [[header-unit]] name = ['quote', 'HeadersBase.h'] ifc = 'C:\...\Debug\HeadersBase.h.ifc' # Using literal strings [[module]] name = 'ModuleBase' ifc = 'C:\...\Debug\ModuleBase.ixx.ifc'
I used
/ifcMap mapfile.ifc
in the command line, and get additional errors.Error (active) E3343 command-line error: no mapping specified for Test Warning C5210 '...\HeadersBase.h.ifc' is not a valid header unit reference; ignoring Test Error C7684 module name 'ModuleBase' has an ambiguous resolution to IFC Test Error C1004 unexpected end-of-file found Test Error C7684 module name 'ModuleBase' has an ambiguous resolution to IFC Test Error C7661 header-name 'HeadersBase.h' has an ambiguous resolution to header 'HeadersBase.h' Test Error C7612 could not find header unit for 'HeadersBase.h' Test
I've spent days on this, and feel like I am getting nowhere.
-
CDev-8220 220 Reputation points
2025-01-11T14:34:06.6266667+00:00 Created a new project.
Placed the ifc files in the project.
Added these files to the project.
Added the files paths to the Additional Module and Header Unit paths.
Immediately the significant error showed up.
Error (active) E3343 command-line error: no mapping specified for 'HeadersBase.h.ifc'
So, this definitely is the issue, I need to solve.
Did I create the ifcMap file correctly, and name it correctly (ifcmap.ifc), or...?
-
Darran Rowe 1,321 Reputation points
2025-01-11T20:11:41.9466667+00:00 It is potentially something else.
I came across an interesting document on the ISO C++ site about building C++ modules in Visual Studio. This can be found here.
Anyway, the very last paragraph states.
"Currently, for a number of reasons which might or might not go away when ifc format is stabilized, C++ intellisense does not use modules created during build even when they exist – it always builds them on its own (and to different locations than the “read” build). So with the externally supplied modules it is critical that we are able to find module source as well as compilation options, module dependencies & includes and be able to re-compile them."
So I am wondering if this is a case of Visual Studio itself is complaining because it cannot create its own copy of HeadersBase.h.ifc.
Sign in to comment