1

I tried to build a native addon for node that runs on Windows and Linux. My addon needs access to libnfc. I compiled libnfc (and dependencys) on windows and linux. On windows I copyed the following files into my node-project:

"libnfc.dll", "libnfc.lib", "libusb.lib", "libusb0.dll" (libusb is used by libnfc)

My bindings.gyp looks like follows:

{
    "variables": {
    "build_files": ["libnfc.dll"]
    },
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "addon.cc" ],

      "include_dirs": [
        "<!(node -e \"require('nan')\")",
        "./nfc_include"
      ],

      'conditions': [
        ['OS=="linux"', {
          'libraries': [
            '-lnfc'
          ]
        }],
        ['OS=="win"', {
          'libraries': [
            '-llibnfc'
          ]
        }]
      ]  
    }
  ]
}

I still have trouble to properly link against that library, because the search path seems to be (after some try and error) "project-directory/build". Rebuild will delete any files in that folder, so I have to recopy the .lib files and then use "node-gyp build" (not "rebuild") again. The "build_files"-flag which should copy the set files to the build directory does not work.

With that trick "node-gyp" successfull builds my addon. But trying to run it I get the following error:

D:\Projekte\iRobot\hg_mRobot\NodeJs\NfcEmulateModule\node_modules\bindings\bindings.js:83
        throw e
              ^
Error: no error
D:\Projekte\iRobot\hg_mRobot\NodeJs\NfcEmulateModule\build\Release\addon.node
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at bindings (D:\Projekte\iRobot\hg_mRobot\NodeJs\NfcEmulateModule\node_modul
es\bindings\bindings.js:76:44)
    at Object.<anonymous> (D:\Projekte\iRobot\hg_mRobot\NodeJs\NfcEmulateModule\
addon.js:1:94)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)

D:\Projekte\iRobot\hg_mRobot\NodeJs\NfcEmulateModule>

Actually I have no idea whats the problem. I tryed to copy the ".lib" and ".dll" files to any folder of my project -> No change. On Linux it works fine! I think I'm still doing something wrong linking the library or the module does not find the required dll's.

Can someone help?

0 Answers0