簡體   English   中英

如何將FFI連接到Node-Webkit(NWJS)?

[英]How to connect ffi to node-webkit(nwjs)?

因此,我嘗試在我的node-webkit(nwjs)應用程序中使用ffi,但是我的代碼不起作用。 有我的index.html文件:

 <!DOCTYPE html> <html> <head> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> <script> var ffi = require('ffi'); var ref = require('ref'); var int = ref.types.int; var platform = process.platform; var mathlibLoc = null; if (platform === 'win32') { mathlibLoc = './math.dll'; } else if (platform === 'linux') { mathlibLoc = './math.so'; } else if (platform === 'darwin') { mathlibLoc = './math.dylib' } else { throw new Error('unsupported plateform for mathlibLoc') } var math = ffi.Library(mathlibLoc, { "add": [int, [int, int]], "minus": [int, [int, int]], "multiply": [int, [int, int]] }); var result = null; result = math.add(5, 2); console.log('5+2=' + result); result = math.minus(5, 2); console.log('5-2=' + result); result = math.multiply(5, 2); console.log('5*2=' + result); </script> </body> </html> 

非常有趣的是我的腳本不起作用,然后我嘗試編寫此行

var ffi = require('ffi');

而且無論我試圖在此行之后運行什么,它都行不通...

因此,在挖完所有Internet之后,我發現我需要以某種方式使用nw-gyp。 首先,我在項目文件夾中運行此命令

npm安裝ffi

然后,我轉到文件夾./node_modules/ffi並嘗試運行此命令:

nw-gyp重建--target = 0.30.0 --arch = x64

而我的控制台中有什么:

gyp info it worked if it ends with ok
gyp info using nw-gyp@3.6.3
gyp info using node@8.11.1 | win32 | x64
gyp info spawn D:\Python27\python.EXE
gyp info spawn args [ 'C:\\Users\\dchar\\AppData\\Roaming\\npm\\node_modules\\nw-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\dchar\\Desktop\\nwjsdll\\node_modules\\ffi\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\dchar\\AppData\\Roaming\\npm\\node_modules\\nw-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\dchar\\.nw-gyp\\0.30.0\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\dchar\\.nw-gyp\\0.30.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\dchar\\AppData\\Roaming\\npm\\node_modules\\nw-gyp',
gyp info spawn args   '-Dnode_lib_file="C:\\Users\\dchar\\.nw-gyp\\0.30.0\\<(target_arch)\\node.lib"',
gyp info spawn args   '-Dnw_lib_file="C:\\Users\\dchar\\.nw-gyp\\0.30.0\\<(target_arch)\\nw.lib"',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\dchar\\Desktop\\nwjsdll\\node_modules\\ffi',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '-Dv13=1',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Users\\dchar\\Desktop\\nwjsdll\\node_modules\\ffi\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  Building assembly file ..\..\..\deps\libffi\src\x86\win64.asm
   Assembling: ..\..\..\deps\libffi\src\x86\win64.asm
  prep_cif.c
  types.c
  raw_api.c
  java_raw_api.c
  closures.c
  ffi.c
  win_delay_load_hook.cc
  ffi.vcxproj -> C:\Users\dchar\Desktop\nwjsdll\node_modules\ffi\build\Release\\libffi.lib
  ffi.cc
  callback_info.cc
  threaded_callback_invokation.cc
  win32-dlfcn.cc
  win_delay_load_hook.cc
..\src\ffi.cc(111): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\ffi.cc(114): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\ffi.cc(123): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\ffi.cc(124): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\ffi.cc(125): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\ffi.cc(126): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\ffi.cc(132): error C2039: 'ForceSet': is not a member of 'v8::Object' [C:\Users\dchar\Desktop\nwjsdll\node_modul
es\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\.nw-gyp\0.30.0\deps\v8\include\v8.h(3103): note: see declaration of 'v8::Object'
..\src\callback_info.cc(63): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\dchar\Desktop\nwjs
dll\node_modules\ffi\build\ffi_bindings.vcxproj]
..\src\ffi.cc(58): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'C:\U
  sers\dchar\Desktop\nwjsdll\node_modules\nan\nan.h(1618): note: see declaration of 'Nan::Callback::Call'

..\src\ffi.cc(59): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
..\src\callback_info.cc(73): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\dchar\Desktop\nwjs
dll\node_modules\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
  C:\Users\dchar\Desktop\nwjsdll\node_modules\nan\nan.h(1618): note: see declaration of 'Nan::Callback::Call'
..\src\ffi.cc(60): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
..\src\callback_info.cc(78): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\dchar\Desktop\nwjs
dll\node_modules\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'C:\U
  sers\dchar\Desktop\nwjsdll\node_modules\nan\nan.h(1618): note: see declaration of 'Nan::Callback::Call'

..\src\ffi.cc(63): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(64): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(65): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(78): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(88): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(91): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(94): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(97): warning C4996: 'Nan::ForceSet': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_modules
\ffi\build\ffi_bindings.vcxproj]
  c:\users\dchar\desktop\nwjsdll\node_modules\nan\nan_maybe_43_inl.h(130): note: see declaration of 'Nan::ForceSet'
..\src\ffi.cc(367): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\dchar\Desktop\nwjsdll\node_
modules\ffi\build\ffi_bindings.vcxproj]
  C:\Users\dchar\Desktop\nwjsdll\node_modules\nan\nan.h(1618): note: see declaration of 'Nan::Callback::Call'
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\dchar\AppData\Roaming\npm\node_modules\nw-gyp\lib\build.js:261:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "D:\\nodejs\\node.exe" "C:\\Users\\dchar\\AppData\\Roaming\\npm\\node_modules\\nw-gyp\\bin\\nw-gyp.js" "rebuild" "--target=0.30.0" "--arch=x64"
gyp ERR! cwd C:\Users\dchar\Desktop\nwjsdll\node_modules\ffi
gyp ERR! node -v v8.11.1
gyp ERR! nw-gyp -v v3.6.3
gyp ERR! not ok

請幫幫我!

nw-gyp不適用於node-WebKit 0.23.0+版本,因此,這就是您需要使用0.22.3版本的原因,因為它是可與nw-gyp一起使用的最后一個版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM