将x86 C dll符号包装到nodejs javascript中

时间:2015-02-12 10:59:08

标签: javascript c++ c node.js node-gyp

我有一个用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,而不适用于使用visual studio 2012的Windows 7.1。您可以查看https://github.com/JuanTrochez/sandbox/tree/master/node/dll_module的确切代码。 感谢。

0 个答案:

没有答案