Native Node Addon Dependency Not linking inside Electorn


#1

Hi, I m trying to develop a native node addon with OpenCV (C++ library)as a dependency. while running addon in node command line everything works fine. But as soon as I use that addon inside electron it’s throwing an error or crashing.
I m trying to use an OpenCV function which uses FFMPEG or GStreamer to get video. some time’s error indicates that FFmpeg library is not available inside the electron.
How is running Native node module inside electron is different from running in command line?. I m specifying all required dependent c++ libraries in binding. gyp file.
As mentioned already everything works fine in cmd line but not electron. Any help in this regard is much appreciated.


#2

Electron uses a slightly different ABI (application binary interface) than vanilla Node.js, so you need to recompile native dependencies against the right headers for your Electron runtime. Here’s the documentation about this:

https://electronjs.org/docs/tutorial/using-native-node-modules

Mentioned in here is a utility that might make this easier for you, depending on your specific build setup:

As an example of how you can include this, @atom/watcher, which is a native node module that’s intended for use within Atom, specifies electron-rebuild as a devDependency and uses a package.json run script as an entry point:


#3

Thanks for the reply. I already used electron-rebuild.
"electron-rebuild": "^1.8.2",

command used to build my addon

./node_modules/.bin/electron-rebuild

I got the same above mentioed error.so I tried a version of vanilla nodejs same as that of electron’s. still it’s not working.


#4

:thinking:

electron-rebuild accepts an argument to determine the target Electron version. Are you certain that it matches… ? I’m reaching a little here.

What’s the specific error message that you see? Or can you find any more information about the crashes, like a stack trace with WinDbg?


#5

I tried multiple things

  1. vanilla nodejs 10.2.0(which was used by the latest stable version of the electron) has a header file issue for native addon.it’s only fixed in 10.2.1 so I cannot use that to match target electron version directly.so I used 10.2.1 and used electron-rebuild to compile it to match electron’s 10.2.0

  2. I tired with node version 10.11.0 along with the latest nightly build of electron 4(which also uses 10.11.0)

I use a c++ library (OpenCV) in electron .this library, in turn, has a transitive dependency which I mentioned in binding. gyp file. when I check the linked libraries for my .node file all my dependencies are linked properly
ldd my node.addon and as mentioned it running in vanilla nodejs. But in electron, it’s crashing

I am getting an error that one of my dependent libraries FFMPEG is not available.it is installed and linked with my addon.only inside electron I m getting this error

Unable to stop the stream: Inappropriate ioctl for device

I don’t know how to get stack trace in ubuntu. can suggest a tool/library for Linux like WinDbg?


#6

Oh! Interesting. You aren’t seeing a crash on load, but a crash during use that doesn’t manifest from node. I also have no idea why I assumed you were on Windows. Crossing contexts in my head I think.

can suggest a tool/library for Linux like WinDbg?

You could run the process under a C++ debugger like lldb or gdb. There is a substantial learning curve though I’m afraid.

You can also get stack traces from native crashes by creating a core file:

ulimit -c unlimited

Once you have a core file from the crash, you can load it into gdb and get the stack trace that way:


#7

Thanks, Ash Wilson. Let me try this out. it’s weird how the same code is working in native nodejs, not the electron.