1

在过去的几个小时里,我试图node-gd在 Windows 上运行。我尝试了几个 repos,终于找到了https://github.com/mikesmullin/node-gd。当我跑

`npm install node-gd`

我收到以下错误:

node-gyp rebuild

...node_modules\node-gd>node "C:\Program Files\nodejs\node_modules\npm\
bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
  node-gd.cpp
..\cpp\node-gd.cpp(17): fatal error C1083: Cannot open include file: 'gd.h': No
 such file or directory [...\node_modules\node-gd\build\node_gd.vcxproj
]

我以为我应该安装gdlib,但是当我用谷歌搜索它时,几乎所有信息php_gd都不是关于 lib 本身的。

我应该把gd文件放在哪里?

编辑:我编译它!现在我得到:

在此处输入图像描述

4

1 回答 1

3

我最近经历了这个过程并遇到了同样的问题,但找不到任何已发布的解决问题的步骤。我意识到这个线程现在已经有将近 1.5 年的历史了,但我会在这里发布我的完整安装步骤,以期它会帮助其他人。

这假设您已经构建了 GD 库 ( https://github.com/libgd/libgd/releases ),并且将使用 GD DLL。

  1. 从https://www.npmjs.com/package/node-gd下载 node-gd 包

    注意:不要在提示符下运行“npm install node-gd”,因为这会自动下载并运行安装。您需要先对包进行一些本地更改,然后将其安装在本地。

  2. 解压后,打开 binding.gyp 文件,例如位于 (downloads_folder)\node-gd\binding.gyp

  3. 更改此行:

    "libraries": ["-lgd"],
    

    到已编译的 GD DLL 导入库的名称,例如“libgd.lib”:

    "libraries": ["-llibgd"],
    
  4. 将 GD 源路径添加到“include_dirs”,例如:

    "include_dirs": [
      "<!(node -e \"require('nan')\")",
      "(path_to_gd)/src" # <-- THIS ENTRY
    ],
    
  5. 将GD编译的库目录添加到Windows的“条件”字段下的VS链接器设置中,例如:

    注意:由于某种原因,我无法通过 gyp 的常规绑定规范使库目录正常工作,所以我不得不求助于这个......

    "conditions": [
      [ "OS=='freebsd'", {
        "libraries": ["-L/usr/local/lib"],
        "include_dirs": ["/usr/local/include"]
      }],
      [ "OS=='mac'", {
        "libraries": ["-L/usr/local/lib", "-L/opt/local/lib"],
        "include_dirs": ["/usr/local/include", "/opt/local/include"]
      }],
      [ "OS=='win'", { # <-- THIS ENTRY
        "msvs_settings": {
          "VCLinkerTool": {
            "AdditionalOptions": ["/LIBPATH:(path_to_gd)/build_msvc12_x64"],
          },
        },
      }],
    ]
    
  6. 保存 binding.gyp 文件,并在本地安装包,例如:

    npm install (downloads_folder)\node-gd
    
  7. 如果您此时尝试使用 node-gd(通过 require),您将收到 OP 遇到的“找不到模块”错误。问题不是找不到模块,而是找不到GD DLL(错误消息很糟糕)。因此,将 GD .dll 文件复制到 node-gd 输出目录(它需要在刚刚构建的 node-gd 二进制文件旁边),例如:

    copy (path_to_gd)\build_msvc12_x64\libgd.dll (path_to_node_modules)\node-gd\build\Release\libgd.dll
    
  8. 应该是这样!希望此时一切正常。

于 2015-06-29T21:19:46.207 回答