Search code examples
c++node.jswindowsnode-gypnode.js-addon

CFLAGS not working on Windows when compiling with node-gyp


For some reason when I compile using node-gyp on Windows, CFLAGS are ignored. Does anyone maybe know the reason? This is my code:

Binding.gyp

{
  "targets": [
    {
      "target_name": "helloWindows",
      "sources": [ "helloWindows.cpp" ],
      "cflags": [ "-D_MY_FLAG"],
    }
  ]
}

helloWindows.cpp

using namespace v8;

#if defined(_MY_FLAG) 
void SuperFunction(const v8::FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);

  args.GetReturnValue().Set(String::NewFromUtf8(isolate, "Hello Antirreni!"));

}

void init(Handle<Object> target) {
    NODE_SET_METHOD(target, "hello", SuperFunction);
}

NODE_MODULE(helloWindows, init);

#endif

Thanks in advance :)


Solution

  • Solved with:

    "defines":["_MY_FLAG"]