防止在自定义 node.js 构建中创建控制台窗口

防止在自定义 node.js 构建中创建控制台窗口

问题描述:

我正在创建 node.js 的自定义构建,它不应向用户显示控制台窗口.

I'm creating a custom build of node.js that should not show a console window to the user.

我尝试更改 gyp 文件中的 链接器配置2(应该设置链接器 flag /SUBSYSTEM:WINDOWS),但是当我运行生成的 node.exe 二进制文件时,我仍然看到一个控制台窗口.

I've tried changing the linker config in the gyp file to 2 (which should set the linker flag /SUBSYSTEM:WINDOWS), but I still get a console window when I run the resulting node.exe binary.

如何防止控制台窗口出现?

How can I prevent the console window from appearing?

进一步调查显示 node.gyp 中的链接器配置未生效.生成的node.vcxproj还有 Console(这对我来说很奇怪,因为添加了'UACUIAccess': 'true' 在 node.gyp 的同一部分确实生效),因此构建的二进制文件链接不正确.

Further investigation reveals that the linker config in node.gyp is not taking effect. The generated node.vcxproj still has <Link><SubSystem>Console</SubSystem></Link> (which is very strange to me, since adding 'UACUIAccess': 'true' in the same part of node.gyp did take effect), so the built binary is incorrectly linked.

看来你必须:

  • Comment out the 'SubSystem': 1 line in common.gypi. (Changing it to 2 causes the build to fail in mksnapshot.)
  • Change SubSystem to 2 in node.gyp
  • Also add 'EntryPointSymbol': 'wmainCRTStartup' to node.gyp.

这会构建一个不创建控制台窗口的 node.exe.

This builds a node.exe that does not create a console window.