Question

In the past few hours I'm trying to run node-gd on windows. I've tried several repos and finally found https://github.com/mikesmullin/node-gd. When I run

`npm install node-gd`

I'm getting the following error:

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
]

I thought I should install gd lib, but when I googled it, almost all information is about php_gd not about the lib itself.

Where should I put the gd files?

Edit: I compiled it! Now I'm getting:

enter image description here

Was it helpful?

Solution

I went through this process recently and encountered the same issues, but wasn't able to find any posted steps for resolving the problems. I realize this thread is nearly 1.5 years old now, but I'll post my complete installation steps here on the chance it'll help someone else.

This assumes you already have the GD library built (https://github.com/libgd/libgd/releases), and will be using the GD DLL.

  1. Download the node-gd package from https://www.npmjs.com/package/node-gd

    Note: Don't run "npm install node-gd" from a prompt, as this will automatically download and run the install. You need to make some local changes to the package first, then install it locally.

  2. After extraction, open the binding.gyp file, e.g. located at (downloads_folder)\node-gd\binding.gyp

  3. Change this line:

    "libraries": ["-lgd"],
    

    to the name of the GD DLL import library that was compiled, e.g. for "libgd.lib":

    "libraries": ["-llibgd"],
    
  4. Add the GD source path to "include_dirs", e.g.:

    "include_dirs": [
      "<!(node -e \"require('nan')\")",
      "(path_to_gd)/src" # <-- THIS ENTRY
    ],
    
  5. Add the GD compiled library directory to the VS linker settings under the "conditions" field for windows, e.g.:

    Note: For some reason I couldn't get the library directory to work correctly via gyp's conventional binding specifications, so I had to resort to this...

    "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. Save the binding.gyp file, and install the package locally, e.g.:

    npm install (downloads_folder)\node-gd
    
  7. If you try to use node-gd at this point (via require) you'll get the "module could not be found" error the OP was getting above. The problem isn't that the module can't be found, it's that it can't find the GD DLL (the error message is terrible). So, copy the GD .dll file to the node-gd output directory (it needs to be next to the node-gd binary files that were just built), e.g.:

    copy (path_to_gd)\build_msvc12_x64\libgd.dll (path_to_node_modules)\node-gd\build\Release\libgd.dll
    
  8. That should be it! Hopefully everything works at this point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top