Search code examples
c++cnode.jsnpmnode-gyp

Compile C/C++ files on target platform without node-gyp


I have some C/C++ code that I need to compile for target platforms (MacOS, Linux flavors, etc). However, it isn't for Node.js bindings, just some scripts written in C, so I don't absolutely need to use node-gyp to do this.

My question is - what is the best way to compile these C scripts if they are packaged in an NPM package. Should I just use the postinstall script to compile the C code? What is best practice here?


Solution

  • What is the best way to compile these C scripts if they are packaged in an NPM package

    This tasks generally solved by crossplatform build systems like automake, cmake, qmake and so on.

    Create an independent c++ package with configured build environment. Add to npm package checking that your program compiled from c++ is available. Show error message if it is not available and notice where to find it and mention in doc about how to compile and install.