Skip to content

Commit d3cb174

Browse files
H. Peter Anvin (Intel)Copilot
andcommitted
compiler.h/file.c: include <windows.h> before Windows SDK headers
nasmlib/file.c included <stringapiset.h> directly (for MultiByteToWideChar()/CompareStringOrdinal()) without first including <windows.h>. Windows SDK headers like <stringapiset.h> are only guaranteed to work when pulled in through the normal <windows.h> pipeline, which sets up SDK-internal architecture macros (_X86_, _AMD64_, ...) derived from the compiler's own _M_IX86/_M_X64/etc. Including them directly skips that setup and can fail with a 'No Target Architecture' #error from <winnt.h> -- which is exactly what happened building with a real cl.exe/nmake in CI. Move the fix to include/compiler.h, since <windows.h> is needed broadly for Windows-specific functionality and other source files may hit the same problem in the future. Include it (with WIN32_LEAN_AND_MEAN) right after the _MBCS define, guarded by _WIN32, before anything else gets a chance to include a Windows SDK header on its own. file.c's direct <stringapiset.h> include is now redundant and removed; <wchar.h> is kept since it's still used for the wchar_t type. Confirmed fixed with a real MSVC (cl.exe/nmake) build in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e2f38a8 commit d3cb174

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

include/compiler.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
/* On Microsoft platforms we support multibyte character sets in filenames */
2525
#define _MBCS 1
2626

27+
/*
28+
* On Windows, a number of source files need Windows API declarations
29+
* (e.g. MultiByteToWideChar(), CompareStringOrdinal()) that live in SDK
30+
* headers such as <stringapiset.h>. Those headers are only guaranteed
31+
* to work when included via the normal <windows.h> pipeline, which sets
32+
* up SDK-internal architecture macros (_X86_, _AMD64_, ...) that plain
33+
* compiler-provided macros (_M_IX86, _M_X64, ...) do not satisfy on
34+
* their own; including them directly can fail with "No Target
35+
* Architecture" errors from <winnt.h>. Pull in <windows.h> once, here,
36+
* before anything else gets a chance to jump the queue.
37+
*/
38+
#ifdef _WIN32
39+
# define WIN32_LEAN_AND_MEAN
40+
# include <windows.h>
41+
#endif
42+
2743
#include "autoconf/attribute.h"
2844

2945
#ifdef HAVE_CONFIG_H

nasmlib/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
*/
4646
#ifdef _WIN32
4747
#include <wchar.h>
48-
#include <stringapiset.h>
48+
/* <windows.h> (which brings in MultiByteToWideChar()/CompareStringOrdinal()
49+
via <stringapiset.h>) is already included by "compiler.h". */
4950

5051
typedef wchar_t *os_filename;
5152
typedef wchar_t os_fopenflag;

0 commit comments

Comments
 (0)