node.js - Electron 原生插件在Windows上失败

标签 node.js windows openssl electron node-gyp

我有一个本地插件,该插件在未包装的 Electron 应用程序上使用openSSL库。
在Windows 10上可以正常工作,在Windows 7上不能正常工作,我收到以下消息:

    Error: The specified module could not be found.
    \\?\C:\Program Files (x86)\AppX Player\resources\app\src\addon\foo.node
        at Error (native)
        at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:167:20)

        at Object.Module._extensions..node (module.js:568:18)
        at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:167:20)
        at Module.load (module.js:458:32)
        at tryModuleLoad (module.js:417:12)
        at Function.Module._load (module.js:409:3)
        at Module.require (module.js:468:17)
        at require (internal/module.js:20:19)
        at Object.<anonymous> (C:\Program Files (x86)\AppX Player\resources\app\s
    rc\addon\index.js:11:3)

我的目标是 Electron 的Windows ia32架构,并按以下方式重建它:
  node-gyp rebuild --target=1.3.1 --arch=ia32 --dist-url=https://atom.io/download/atom-shell --verbose

该文件的binding-gyp如下所示,基于this。它使用openSSL静态库

{
            "targets": [
                {
                    "target_name": "addon",
                    "sources": [ 
                        "./src/encryptor.cpp" ,
                        "./src/EncryptorHandler.cpp",
                        "./src/SetupHandler.cpp",
                        "./src/RC4Handler.cpp",
                        "./src/HardwareInfoHandler.cpp",
                        "../Encryptions/RC4.cpp",
                        "../Encryptions/AES.cpp",
                        "../Encryptions/utils.cpp",
                        "../oggEncDec/src/FileHandler.cpp",
                        "../oggEncDec/src/OGGSelectiveEncryptor.cpp",
                        "../machineIdentification/common.cpp"
                    ],
                    "cflags!": [ "-fno-exceptions" ],
                    "cflags_cc!": [ "-fno-exceptions" ],
                    'cflags': ['-fexceptions'],
                    'cflags_cc': ['-fexceptions -Wall -Wextra -Wconversion'],
                    "include_dirs": [
                        "<!(node -e \"require('nan')\")",
                        "../"
                    ],
                    'conditions': [
                        ['OS=="linux"', {
                                "sources": [ 
                                    "../machineIdentification/linuxHardwareInfo.cpp"
                                ],
                                'libraries': [ 
                                    '-lcrypto',
                                ],
                            }
                        ],
                        ['OS=="mac"', {
                                "sources": [ 
                                    "../machineIdentification/macHardwareInfo.cpp"
                                ],
                                'libraries': [ 
                                    '-lcrypto',
                                ],
                        }],
                        ['OS=="win"', {
                            'msvs_settings': {
                                'VCCLCompilerTool': {
                                    'AdditionalOptions': [ '/EHsc' ],
                                    'ExceptionHandling': 1
                                }
                            },
                            "sources": [ 
                                "../machineIdentification/windowsHardwareInfo.cpp"
                            ],
                            'conditions': [
                                # "openssl_root" is the directory on Windows of the OpenSSL files.
                                # Check the "target_arch" variable to set good default values for
                                # both 64-bit and 32-bit builds of the module.
                                ['target_arch=="x64"', {
                                    'variables': {
                                        'openssl_root%': 'C:/OpenSSL-Win64'
                                    },
                                }, {
                                    'variables': {
                                        'openssl_root%': 'C:/OpenSSL-Win32'
                                    },
                                }],
                              ],
                              'libraries': [ 
                                '-l<(openssl_root)/lib/libeay32.lib',
                              ],
                              'include_dirs': [
                                '<(openssl_root)/include',
                              ],
                        }]
                  ]
                }
            ]
        }

万一它丢失了一个dll(以防止我链接静态库),我在exe的同一级别上添加了openSSL dll。还有什么可能导致此行为?

编辑
安装OpenSSL二进制文件可以正常工作,我认为静态链接可以解决这一问题,因此我不会依赖于外部dll的

编辑2
如果我可以打包静态库并将其 bundle 在“.node”文件中,那么一切都会解决。在.node文件上使用dependency walker告诉我它需要dll,而我需要的是在上面具有dll代码。

最佳答案

原来http://slproweb.com/products/Win32OpenSSL.html上的库似乎只是围绕仍在使用它的dll的包装。
我误以为node-gyp只是在编译东西而没有依赖关系,这是不正确的。
我发现了另一个可以完成此操作的预编译的openssl lib here

所以总结一下:
我需要在 Electron 下使用OpenSSL运送某些东西,但 Electron 不会像 Node 那样暴露OpenSSL并将其切换为borinSSL。
我遵循了tooTallNate的文章,该文章推荐了一个静态库,并假定该静态库是正确的,并且我以某种方式需要DLL,并且我假定node-gyp没有 bundle 使用的静态库。
把库换成另一个库(或者最好自己编译)就可以了。

关于node.js - Electron 原生插件在Windows上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38639455/

相关文章:

node.js - 在 scrape-it 中设置用户代理

windows - 在Windows中以cmd打开指定的路径

windows - Vim 。 Windows 中保存的文件的编码问题

ruby - 如何在 rspec 中正确模拟 openssl 对象?

c++ - 查找内存违规/泄漏

javascript - 缩小 NodeJS 中使用的代码是否有意义?

javascript - 如何在 Handlebars 模板中创建自定义 for 循环

javascript - UserModel 不可分配给文档类型的参数 | nulll [带 typescript 的 Mongoose ]

c# - .NET中获取目录数据的最快方法

ssl - Haproxy ssl 配置 - 安装根证书和中间证书