Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using node-gyp Predefined Variable PRODUCT_DIR

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 ?

like image 339
Royal Pinto Avatar asked May 07 '15 15:05

Royal Pinto


People also ask

Is python required for node-gyp?

However, if you are an add-on developer, you probably need to install node-gyp globally. To use node-gyp, first, we'll need to install a Python runtime, the make utility, and a C or C++ compiler.

What is gyp format?

GYP is the abbreviation for Generate Your Projects. The purpose of GYP is to support larger projects compiled on different platforms, such as Mac, Windows, and Linux. It can generate Xcode projects, Visual Studio projects, Ninja compiled files and Makefiles.

Which file does node-gyp use to read the configuration?

The binding.gyp file A binding.gyp file describes the configuration to build your module, in a JSON-like format. This file gets placed in the root of your package, alongside package.json .

What is node-gyp in Nodejs?

node-gyp is a cross-platform command-line tool written in Node. js for compiling native addon modules for Node. js. It contains a vendored copy of the gyp-next project that was previously used by the Chromium team, extended to support the development of Node. js native addons.


1 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 :)

like image 61
eljefedelrodeodeljefe Avatar answered Sep 21 '22 16:09

eljefedelrodeodeljefe