1

I am working on node-ffi module in node.js. In most of the tutorials they have given an example with single library (shared library of C++) only. But, I would like to know how to use two libraries (shared libraries of C++) in node-ffi.

Thanks in advance

2 Answers2

2

We can add as many shared lib with node-ffi.

var ffi = require('ffi');
var ref = require('ref'); //to create references

var ref = require('path');

var libMyLib1 = ffi.Library(path.resolve(__dirname,'./libmyLibrary1'),
{
   'add': ['int', ['int','int']]
});

var result = libMyLib.add(5,10);

var libMyLib2 = ffi.Library(path.resolve(__dirname,'./libmyLibrary2'),
{
  'reverse': ['string', ['string']]
});

var result = libMyLib2.reverse("Hello");
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
vijay negi
  • 21
  • 3
0

No we cannot add two or more libraries in node-ffi. we can mention only one library at once in node-ffi.

var FFI = require('ffi');

var libVarForNodeJS = FFI.Library('libraryname',{
                    'libraryfunction':['void', []]
});

Another choice is , if you have different c++ files than just create one.so file for all these files.

Vishnu Shekhawat
  • 1,245
  • 1
  • 10
  • 20
  • If one wants to "load libA which depends on libB", one needs [workaround](https://stackoverflow.com/a/72539828/4123703) – Louis Go Jun 08 '22 at 03:50