电子本机插件在 windows 上失败

Electron native addon failing on windows

我有一个本机插件,它在解压的电子应用程序上使用 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)

我的目标是 windows electron 的 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 如果我可以打包静态库并将其捆绑在“.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 没有捆绑使用的静态库。 将 lib 换成另一个(或者更好的是自己编译)就可以了。