Home » Nodejs » node-gyp link library dependencies at build time

node-gyp link library dependencies at build time

Posted by: admin November 30, 2017 Leave a comment


My nodejs addon uses cares library and my binding.gyp has dependencies attribute which is pointing to this. Now whenever I have to run addon, I have to export LD_LIBRARY_PATH variable.

Is there a way I can configure this in binding.gyp so that every time I don’t have to set LD_LIBRARY_PATH. (Linking at build time)

Dependency setting in binding.gyp: "dependencies": [ "deps/cares/cares.gyp:cares" ]

Ex export: export LD_LIBRARY_PATH=build/Release


"libraries": [ "-Wl,-rpath,./build/Release/" ]

Worked for me on Mac as well as Linux(Ubuntu).


My answer to how to add dependence to static library in binding.gyp node-gyp for node.js extension seems to apply here as well, and should be cross platform.

In short it uses the module_root_dir and builds an absolute path.

"libraries": [


I have had success obtaining a relative path in Ubuntu & Debian using the following binding.gyp line:

"libraries": [ "../lib/somelib/somelib.a" ]

My folder structure looks like this:


I got the method (somewhat indirectly) from here:

Leave a Reply

Your email address will not be published. Required fields are marked *