Trevor
Trevor

Reputation: 1419

How do I specify include and lib paths to node.js npm

I'm trying to install a node.js module (zmq in this case) with npm install. The C lib needed for this module is not installed in a standard location. How do I specify extra include paths and lib paths to npm? I've tried things like "CFLAGS="-I/path/to/include" npm install" with no effect.

Upvotes: 4

Views: 5670

Answers (2)

Leon
Leon

Reputation: 1

Another solution (does not require any file changes) is to use pkg-config's PKG_CONFIG_PATH variable, which should point to the location where the libraries are installed. If zmq has been installed at /opt/zmq then PKG_CONFIG_PATH=/opt/zmq/lib/pkgconfig pkg-config libzmq --libs should return -L/opt/zmq/lib -lzmq and npm install can be run with PKG_CONFIG_PATH=/opt/zmq/lib/pkgconfig npm install

Before node app is started LD_LIBRARY_PATH must be set accordingly, i.e: LD_LIBRARY_PATH=/opt/zmq/lib node app.js

Upvotes: 0

IanB
IanB

Reputation: 2694

The zeromq module can be built as follows (other modules may work the same):

  • download the zip file and unpack into a temporary location e.g. /tmp/zeromq.node-master
  • edit the binding.gyp file
  • find the section that corresponds with your OS and add your include -I and library -L paths there.

e.g.

['OS=="linux"', {
  'cflags': [
    '<!(pkg-config libzmq --cflags 2>/dev/null || echo "")',
    '-I/usr/local/zeromq3/include'
  ],
  'libraries': [
    '<!(pkg-config libzmq --libs 2>/dev/null || echo "")',
    '-L/usr/local/zeromq3/lib'
  ],
}],
  • Run npm install on the temporary directory: npm install /tmp/zeromq.node-master

Upvotes: 4

Related Questions