c++ - How can I use environment variable as compile-time constant in native nodejs addon? -
i writing native addon nodejs. how can use environment variable constant @ compile time? is, "inject" constant in nodejs c++ addon environment variable set during node-gyp build
or npm install
. found this answer, far can see, there no equivalent option passing through variables node-gyp
normally when create makefile can pass options compiler like:
-d name=definition
which equivalent of having in source code:
#define name "definition"
so using:
-d name=$name
would put name
environment variable name
constant in compiled source code.
but node-gyp
makefile generated you, see:
you may need change generated makefile after run:
node-gyp configure
but before run:
node-gyp build
or can make simple library entire purpose have given value defined used node addon.
another option have script like:
echo "#define name \"$name\"" > config.h
and can include config.h
file node native addon or other code written in c or c++.
Comments
Post a Comment