Home » Nodejs » Using node-gyp Predefined Variable PRODUCT_DIR

Using node-gyp Predefined Variable PRODUCT_DIR

Posted by: admin November 30, 2017 Leave a comment

Questions:

In binding.gyp I want to set like this:

"libraries": [ "-Wl,-rpath,<working directory>/build/Release/" ]

I am using the following configuration to do the same:

"libraries": [ "-Wl,-rpath,<!(pwd)/build/Release/" ]

This works but the problem with this is that, it would not work on Windows or wherever pwd is not available and also this is not the best option as there is already a predefined variable PRODUCT_DIR available in node-gyp to achieve this. Strangely I am not able to use this variable PRODUCT_DIR.

I tried following options but no luck. error says Library not loaded: @rpath/<lib>.dylib (rpath is not getting set):

  • "libraries": [ "-Wl,-rpath,>(PRODUCT_DIR)/build/Release/" ]
  • "libraries": [ "-Wl,-rpath,<(PRODUCT_DIR)/build/Release/" ]
  • "libraries": [ "-Wl,-rpath,>(PRODUCT_DIR)"]
  • "libraries": [ "-Wl,-rpath,<(PRODUCT_DIR)"]

When i tried printing by "<!(echo <(PRODUCT_DIR) 1>&2)" it says builddir: command not found. Looks like variable has value builddir.
Shouldn’t it print the target directory instead of builddir ? or builddir means something for compiler ?

Am I not using this variable properly or is there any other variable available that I should be using ?

Answers:

PRODUCT_DIR behaves really weird, I got to say. I avoid it wherever possible. Often by writing external build scripts with plain node.

The reason why you can’t "<!(echo <(PRODUCT_DIR) 1>&2)" is that is some kind of special variable to node-gyp.

However you are using the right format, like here

{
   'files': [ '<(PRODUCT_DIR)/libzip.dll' ],
   'destination': '<(module_path)'
}

My guess though is that you need to…

"variables": {
    "YOUR_DIR: "<(PRODUCT_DIR)/build/Release/"",
    "your_libs": "-Wl,-rpath,<(CURRENT_DIR) ]"
}

You know, it’s Python, we don’t know about 🙂