0

I'm making a nodejs app that have to pull data from a NI USB 6210. National Instruments, gives away a bunch of examples that use their (pure) C libs, since, I'm on nodejs, I thought I could "easily" recycle them into a node module using node-gyp, but I discovered that node modules are more likely to be written in C++, rather than plain C (as described in the reference), so I was wondering about other possible solutions. Aside from that the whole library thing is also based on a bunch of frameworks ( on OSX )

    /Library/Frameworks/nidaqmxbase.framework
    /Library/Frameworks/nidaqmxbaselv.framework
    /Library/Frameworks/lib67xx.framework
    /Library/Frameworks/libDIO96.framework
    /Library/Frameworks/libESeries.framework
    /Library/Frameworks/libmiteDma.framework
    /Library/Frameworks/libMSeries.framework
    /Library/Frameworks/libSSeries.framework
    /Library/Frameworks/libUSB-92xx.framework

so my second question is how does the frameworks interact with nodejs? I've a little bit of confusion about this.

UPDATE

Thanks to @mscdex I've built my first node module that should just wrap the frameworks and make'em available on the node side. This is what I've done so far:

binding.gyp

{
    "targets": [
        {
            "target_name": "addon",
            "sources": [

            ],
            "include_dirs": [
                "./includes/NIDAQmxBase.h"
            ],
            "conditions": [
                [
                    "OS=='mac'",
                    {
                        "defines": [
                            "__MACOSX_CORE__"
                        ],
                        "architecture": "i386",
                        "link_settings": {
                            "libraries": [
                                "-framework",   
                                "nidaqmxbase",
                                "-framework",
                                "nidaqmxbaselv"
                            ]
                        }
                    }
                ]
            ]
        }
    ]
}

with this I've run the configure and the build commands

to be noticed that I'm using nw-gyp that is a hack of the node-gyp, because I need to build a module for node-webkit, but it's just like node-gyp with a few improvements.

This operation produced a file called addon.node (weighted 8kb)

After that I've tried to run a simple js test file

var ni = require('./libs/addon');

console.log(ni);

as I ran this it produced

Error: Symbol addon_module not found.
    at Module.load (module.js:352:32)
    at Function.Module._load (module.js:308:12)
    at Module.require (module.js:360:17)
    at require (module.js:376:17)
    at window.require (eval at undefined, <anonymous>:1:112)
    at eval (file:///Users/myUser/MyPath/MyNodeWebkitProject/public/js/ni-daqmx.js:1:10)

and that is where I'm stuck.

holographix
  • 2,497
  • 2
  • 32
  • 46
  • You should post the actual addon source somewhere. – mscdex May 20 '14 at 16:38
  • the addon has no source atm, since all the functions I need are the one declared in the frameworks. I was looking at a real-life example of library wrapping https://github.com/arturadib/node-qt and it seems that they just link the frameworks without any further ado.. – holographix May 20 '14 at 16:39
  • Well that's your problem :-). You have to follow the structure of a node addon and you will have to wrap the functions you want. There is no automatic wrapping of functions from javascript (like libffi). In the case of node-qt, they do wrap each of the QT functions (look in `src/QtGui` for example). – mscdex May 20 '14 at 16:40
  • k cool I'll try to stick to it and see what's coming.. – holographix May 20 '14 at 16:44
  • You may also want to take a look at the node docs' [addon section](http://nodejs.org/docs/latest/api/addons.html) if you haven't already. – mscdex May 20 '14 at 16:47
  • yeah it's the link I've already posted in the question, I'll look more deeper into it anyway. thx! – holographix May 20 '14 at 18:46

1 Answers1

1

You can use/wrap C libraries in node (C++) with no problem.

As far as the frameworks go, you should be able to add those files as libraries in your binding.gyp file and gyp should automatically convert them to -framework lib67xx -framework libDIO96 ... linker flags.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • that was quick! I'll give it a shot – holographix May 20 '14 at 13:51
  • although I link all the libraries ( -framework ) I should bind each and every function in those libs in order to be able to use them on the node.js side, right? So this will be something like a single c++ file that makes only those binding, since that is the only thing that I need? Sorry to bother u like that, but this is my first time module :) Thx a ton anyway! – holographix May 20 '14 at 14:21
  • I haven't had too much experience with framework files, but I would think you would just include the frameworks that you are actually using and just use the functions you need/want? – mscdex May 20 '14 at 14:27
  • sorry to let you down, but it's not working now that I've compiled it and I'm testing it in node it says "addon_module not found", I'm going to update my question so that you can follow along – holographix May 20 '14 at 15:50