2016-07-28 50 views
1

我有一個本地插件,它在解壓後的電子應用程序上使用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) 

我指定一個窗口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丟失(這不應該是因爲我是連接靜態庫),我增加了OpenSSL的DLL上的同一水平可執行程序。還有什麼可能導致這種行爲?

編輯 安裝OpenSSL的二進制文件做它的工作原理,我認爲靜態鏈接會照顧的那個,所以我不會依賴於外部DLL的

編輯2 一切想如果我可以得到解決打包靜態庫並將其捆綁到「.node」文件中。在.node文件中使用dependency walker會告訴我它需要dll,而我需要的是爲它提供dll代碼。

+1

每個OpenSSL配置都不同。一套'CFLAGS'和'CXXFAGS'不會。它尤其適用於32位和64位應用程序。另請參閱[在OS X上構建多元OpenSSL](http://stackoverflow.com/q/25530429)。不要擔心OS X位;相反,關注像BIGNUMs這樣的東西的差異。快速/骯髒的解決方案:爲每個平臺運行'./configure',然後複製'CFLAGS'。配置顯示'CFLAGS',所以它很容易複製/粘貼。 – jww

+0

請看看並嘗試理解它,謝謝! – FabioCosta

+0

我檢查與依賴沃克,當我編譯.node它帶有一個dll依賴項,有沒有辦法「複製」鏈接的代碼,所以它被編譯在.node旁邊,我不需要任何DLL? – FabioCosta

回答

0

原來,http://slproweb.com/products/Win32OpenSSL.html上的lib似乎只是一個包裝仍然使用它的dll。 我誤以爲node-gyp只是在沒有依賴關係的情況下編譯這個東西,這是不正確的。 我發現了另一個預編譯的openssl庫文件here

所以結束: 我需要在電子下運送OpenSSL的東西,但電子並不像OpenFlow一樣公開OpenSSL,並將其切換爲borinSSL。 我跟着tooTallNate文章,推薦一個靜態庫,並假設靜態庫是正確的,我不知道需要DLL,我認爲node-gyp沒有捆綁使用的靜態庫。 將lib切換爲另一個(或者更好地編譯它自己)的技巧。