Skip to content

build,tools: fix shared library cross-compile#63963

Open
PickBas wants to merge 1 commit into
nodejs:mainfrom
JaneaSystems:win-dll-fix
Open

build,tools: fix shared library cross-compile#63963
PickBas wants to merge 1 commit into
nodejs:mainfrom
JaneaSystems:win-dll-fix

Conversation

@PickBas

@PickBas PickBas commented Jun 17, 2026

Copy link
Copy Markdown

Fix Windows DLL build

Fixes building Node.js as a shared library on Windows, including cross-compiling (e.g. arm64 on an x64 host).

  • tools/gen_node_def: parse the PE export table statically instead of LoadLibrary/GetProcAddress, so a host-arch tool can read a cross-compiled target-arch libnode.dll. Output is byte-identical to the old tool on native x64 builds.
  • node.gyp: when cross-compiling, build gen_node_def for the host so it can run during the build, and have generate_node_def depend on that host build. Also link Dbghelp.lib, winmm.lib, and Ws2_32.lib into the shared library, and don't define BUILDING_NODE_EXTENSION for node_mksnapshot (it links node_base statically, so its symbols must not be marked dllimport).

Testing

Comparing the original gen_node_def with changed (x64):

C:\dev\node_projects\node> cl /EHsc gen_node_def_orig.cc /Fe:gen_node_def_orig.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36244 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

gen_node_def_orig.cc
Microsoft (R) Incremental Linker Version 14.51.36244.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:gen_node_def_orig.exe
gen_node_def_orig.obj

C:\dev\node_projects\node>gen_node_def_orig.exe out\Release\libnode.dll old.def

C:\dev\node_projects\node>fc old.def out\Release\node.def
Comparing files old.def and OUT\RELEASE\NODE.DEF
FC: no differences encountered

Attempt of .def file generation of the original gen_node_def (arm64):

C:\dev\node_projects\node>gen_node_def_orig.exe out\Release\libnode.dll old.def
ERROR: Failed to load out\Release\libnode.dll

Fixes: #52664

Fixes: nodejs#52664
Signed-off-by: PickBas <sayed.kirill@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory. labels Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-compilation bug when compiling for ARM64 on a non-ARM64 host with Windows

2 participants