9

I am deploying a node-js app to heroku that requires the npm package imagemagic-native.

I made the buildpack install libmagick++-dev and export the include path:

export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:$INCLUDE_PATH"
export CPATH="$INCLUDE_PATH"
export CPPPATH="$INCLUDE_PATH"

Upon installing the imagemagic-native package with npm install, node-gyp is invoked to compile it's binaries. However I get this error:

remote:        > imagemagick-native@1.7.0 install /tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native
remote:        > node-gyp rebuild
remote:        
remote:        make: Entering directory `/tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native/build'
remote:          CXX(target) Release/obj.target/imagemagick/src/imagemagick.o
remote:        In file included from ../src/imagemagick.cc:9:
remote:        ../src/imagemagick.h:1:22: warning: Magick++.h: No such file or directory

This suggests that gcc doesn't see the header files for libmagick++, because $CCPATH is not available to it.

How can I make npm install add the path to the list of include_dirs that node-gyp uses?

More detail about my use case is here: Using Magick++ in a node.js application on heroku

Community
  • 1
  • 1
d_inevitable
  • 4,381
  • 2
  • 29
  • 48

4 Answers4

8

Try:

setting the environment variable CXX=/path/to/g++ -Ipath/to/include

and then restarting the process. If you're using bash this is done by

export CXX="/path/to/g++ -Ipath/to/include"

/path/to/include being where the missing header Magick++.h is located

if that doesn't work you may manually have to set CXX to include the -I in the makefile at /tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native/build then cding into that directory and calling make.

Qwertyzw
  • 530
  • 4
  • 12
7

I've spent some time trying to answer the same question. In the end, i've found the proper way to do this here. You need to set 'include_dirs' property in ~/.node-gyp/x.x.x/common.gypi. This is how I've set the include dir on Mac OS to /opt/local/include/ (which is where all macports intalls go):

...
['OS=="mac"', {
  'defines': ['_DARWIN_USE_64_BIT_INODE=1'],
  'include_dirs': ['/opt/local/include'],
  'xcode_settings': {
    'ALWAYS_SEARCH_USER_PATHS': 'NO',
...

Though I'm not sure it's applicable for heroku environment.

dragn
  • 1,030
  • 1
  • 8
  • 21
1

You can also use the "include_dirs" option in your project binding.gyp file. Read more about available options on the format description page.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
0

You can now do OTHER_CFLAGS='-I/usr/local/include' supposedly. See https://github.com/nickdesaulniers/node-nanomsg/pull/144

Timmmm
  • 88,195
  • 71
  • 364
  • 509