dll 错误
Error: A dynamic link library (DLL) initialization routine failed
依赖的dll未放入目录也会导致模块加载失败
Error: The specified module could not be found.
node.exe 未延迟加载
需要配置下面俩项
#ifdef _MSC_VER
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <delayimp.h>
#include <string.h>
static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo *info) {
HMODULE m;
if (event != dliNotePreLoadLibrary)
return NULL;
if (_stricmp(info->szDll, "NODE.EXE") != 0)
return NULL;
m = GetModuleHandle(NULL);
return (FARPROC)m;
}
decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook;
#endif
node.lib 同函数名依赖顺序问题
查看node.lib导出函数,主要有
uv
openssl
v8
zlib
dumpbin /LINKERMEMBER node.lib >nodelib.txt
修改node.lib为最后依赖
node gyp找不到vs
2017版本后依赖powershell脚本
$ExecutionContext.SessionState.LanguageMode
看看是不是为 FullLanguage
__PSLockdownPolicy 系统环境变量 为 1,如果为4为 ConstrainedLanguage。
另外说明我设置 npm config set msvs_version 2019
无效
二进制文件坑
git 默认换行符自动转换,导致二进制文件失效
关闭转换
git config --global core.autocrlf false
依赖非n-api库比如openssl,uv
cd /path-to-module/
HOME=~/.electron-gyp node-gyp rebuild --target=1.2.3 --arch=x64 --dist-url=https://electronjs.org/headers
只使用 #include <node_api.h>
保证跨版本兼容性