5 Statically linked executable
Yihong Wang edited this page 2018-03-21 10:29:10 -07:00

Node.js has support to be compiled as a fully statically linked executable just by using the --fully-static configure flag. That way it doesn't require external dynamic libraries (.so, .dll, .dylib...) and its main purpose is for embedded platforms. Nevertheless, it's somewhat experimental and has some issues you need to know before using it:

  • It's dependent of the C lib used: the standard glibc (found on Ubuntu, for example) cannot be used to build fully statically linked executables, as some components are designed such that they require loading dynamic libs for some functionality. This doesn't happen with other alternative C libs like musl, uclib or DietLib, for example.
  • It doesn't work with MacOS X developer tools: the vanilla gcc compiler on MacOS X doesn't recognize the -static flag since it's intended to use only dynamic linking. It could work with other compilers (installed with homebrew or macports, for example), but this has not been tested.
  • It could not load C++ Addons: some C libs like musl (and seems glibc too) either use a stripped-down version of the dlopen() function or dynamic loading functionality is stubbed out entirely (at least with musl 1.1.11) when included in statically linked executables, so loading of C++ Addons could fail. Requiring pure Javascript modules will work as expected, though.