javascriptcangularjsnode.jsjsctypes

Call C shared library API (in .so lib) from JavaScript


I have a custom C shared library (.so lib) with some APIs. I want to invoke these APIs from AngularJS (or JS). My constraint is that I should not recompile the shared library code using any other compiler but to use the .so file directly. Given limited options to do so, I experimented using some and planning to use some other but none are satisfactory i.e., they require my shared lib code to be recompiled with their own compiler. My UI application is a Chrome App.

  1. Emscripten works but requires my .so lib to be compiled with emcc compiler. Hence not useful.
  2. Use Google PNaCl which also requires my .so lib to be compiled with its own SDK.
  3. Use Node js and invoke the C APIs from the .so lib directly using node-gyp.
  4. Use js-ctypes and try to invoke C APIs from JS code directly.

I know that first two doesn't work for me. For the third and fourth ones, I am not sure if they work without recompilation of the library code using their own compilers or SDKs. Could you please share some of your expertise on if this is possible or is there any other way to do?


Solution

  • The issue is solved with node-ffi library. We can use node-ffi to invoke C APIs from the shared library.