0

I learned, how to make native c++ addons for node.js, but now I want to make a compiled addon work on linux. I took .node file from the /build/Release folder (I use node-gyp for compiling) and put it in the linux folder. The addon works correctly on windows, but on linux I get this error: Error: /root/folder/addon3.node: invalid ELF header. What does this error mean and how to fix it? I use addon in this way:

const addon3 = require('./addon3.node');
let res = addon3.func(2, 1);
ALEX
  • 55
  • 2
  • 8
  • I'm taking a guess that the .node file you used was compiled on windows, for windows? Short story: the ELF header of a native Linux binary tells the kernel how to execute the binary, so seeing the above error either means you have, eg a 64-bit ELF on 32-bit, or the binary doesn't have a valid ELF header at all. I suggest looking at something like this: https://intellipaat.com/community/14292/cross-compile-node-module-with-native-bindings-with-node-gyp – daf Aug 24 '20 at 19:15
  • As an aside: you're using a cross-platform interpreter (node) and producing binary, platform-dependent addons. Where possible, avoid this -- that's part of the point of using anything with a cross-platform runtime (eg node, java, erlang, python, ruby, .net, etc, etc, etc). If there's a real gain, sure, go for it, but you will then have to (a) compile for and (b) test on other platforms. – daf Aug 24 '20 at 19:19
  • ah.. I understood, .node depends on the system I make it on, so I have to recompile my addon on linux. Thanks – ALEX Aug 24 '20 at 19:58

0 Answers0