将一个x86 C dll符号包装到nodejs javascript中
我有一个用mingw gcc工具链(32位)编译的dll。 我想把一个符号包装到一个javascript函数中。 我做了下面的代码:
binding.gyp
{ "targets": [ { "target_name": "hellomod", "sources": [ "hellomod.cc" ], "include_dirs": [ "<!(node -e \"require('nan')\")" ], "libraries": [ "C:\\juan\\repos\\sandbox\\node\\dll_module\\hello_lib\\hello.lib" ] } ] }
hellomod.cc
#include <nan.h> extern "C" { __declspec( dllimport ) void hello(char *name); } using namespace v8; NAN_METHOD(Method) { NanScope(); hello("Juan"); NanReturnValue(String::New("Hello world")); } void Init(Handle<Object> exports) { exports->Set(NanSymbol("hello"), FunctionTemplate::New(Method)->GetFunction()); } NODE_MODULE(hellomod, Init)
的package.json
{ "name": "hello", "version": "0.0.1", "description": "Mon premier package dll", "main": "index.js", "scripts": { "test": "node index.js" }, "author": "Juan", "license": "MIT", "dependencies": { "nan": "^1.6.1" }, "gypfile": true }
当我执行命令node-gyp rebuild
出现以下错误:
hellomod.obj : error LNK2001: unresolved external symbol __imp_hello [c:\juan\r epos\sandbox\node\dll_module\hello\build\hellomod.vcxproj] c:\juan\repos\sandbox\node\dll_module\hello\build\Release\hellomod.node : fatal error LNK1120: 1 unresolved externals [c:\juan\repos\sandbox\node\dll_module\h ello\build\hellomod.vcxproj]
注意:这个项目在Visual Studio 2010的windows xp 32bits上运行得很好,而在windows 7.1上没有visual studio 2012的效果。你可以看一下https://github.com/JuanTrochez/sandbox/tree/master/node/ dll_module的确切代码。 谢谢。