2014-02-19 147 views
1

在過去的幾個小時內,我試圖在Windows上運行node-gd。我嘗試了幾次回購,最後找到https://github.com/mikesmullin/node-gd。當我運行在窗口上安裝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 
] 

,我想我應該安裝gd lib中,但是當我GOOGLE了它,幾乎所有的信息是關於php_gd不是的lib本身。

我應該在哪裏放置gd文件?

編輯:我編譯了它!現在我越來越:

enter image description here

+0

檢查這個https://github.com/mikesmullin/node-gd/issues/14 – vinayr

+0

@vinayr現在我就在'LINK:致命錯誤LNK1181:無法打開輸入文件 'gd.lib'[ ... \ node_m odules \ node-gd \ build \ node_gd.vcxproj]' – Deepsy

+0

@Deepsy:你有沒有找到任何解決方案? – darma

回答

1

我通過這個過程去最近和遇到同樣的問題,但沒有能夠找到解決問題的任何步驟發佈。我意識到這個線程現在已經有近1.5年的歷史了,但是我會在這裏發佈完整的安裝步驟,以幫助其他人。

這裏假設你已經有了GD庫(https://github.com/libgd/libgd/releases),並且會使用GD DLL。

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

    注意下載節點-GD包裝:不要運行「NPM安裝節點GD」從一個提示,因爲這會自動下載並運行安裝。您需要先對軟件包進行一些本地更改,然後在本地進行安裝。

  2. 提取後,打開binding.gyp文件,例如,位於(downloads_folder)\節點-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編譯庫目錄到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. 如果您嘗試使用節點-GD在這一點上(通過要求),你會得到「模塊無法找到「的錯誤OP正在上面。問題不在於找不到模塊,而是因爲找不到GD DLL(錯誤信息很糟糕)。因此,GD .dll文件複製到節點-GD輸出目錄(它需要旁邊剛剛建造的節點-GD二進制文件),例如:

    copy (path_to_gd)\build_msvc12_x64\libgd.dll (path_to_node_modules)\node-gd\build\Release\libgd.dll 
    
  8. 這應該是它!希望在這一點上一切正常。

+0

所以我瀏覽了我的舊問題,發現我沒有標記這個。我會將此標記爲答案,因爲這是一個可能的解決方案。感謝您的努力。 – Deepsy