为节点 gyp 添加包含目录

Add include dir for node gyp

我正在将一个 node-js 应用程序部署到需要 npm 包的 heroku imagemagic-native

我安装了 buildpack libmagick++-dev 并导出包含路径:

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

使用 npm install 安装 imagemagic-native 软件包后,会调用 node-gyp 来编译它的二进制文件。但是我得到这个错误:

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

这表明 gcc 看不到 libmagick++ 的头文件,因为 $CCPATH 对它不可用。

如何让 npm install 将路径添加到 node-gyp 使用的 include_dirs 列表中?

关于我的用例的更多细节在这里:Using Magick++ in a node.js application on heroku

尝试:

设置环境变量CXX=/path/to/g++ -Ipath/to/include

然后重新启动进程。如果您使用 bash 这是由

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

/path/to/include 是丢失的 header Magick++.h 所在的位置

如果这不起作用,您可能必须手动设置 CXX 以在位于 /tmp/build_720834c3a32b65d69ae603d7c618e20f/node_modules/imagemagick-native/build 的 makefile 中包含 -I,然后进入该目录并调用 make。

我花了一些时间试图回答同样的问题。最后,我找到了执行此操作的正确方法 here。您需要在~/.node-gyp/x.x.x/common.gypi中设置'include_dirs'属性。 这就是我将 Mac OS 上的 include 目录设置为 /opt/local/include/ 的方式(这是所有 macports 安装的地方):

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

虽然我不确定它是否适用于 heroku 环境。

您还可以在项目 binding.gyp 文件中使用 "include_dirs" 选项。在 format description page.

上阅读有关可用选项的更多信息