如何让 node-gyp 在 Windows 7 平台上工作 [英] How do I get node-gyp to work on Windows 7 platform

查看:41
本文介绍了如何让 node-gyp 在 Windows 7 平台上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试编译标准的Hello World"示例 [2] 时,我尝试在 Windows 7 + Node.js 平台上使用 node-gyp 失败 [3].注意:node-gyp 在尝试 npm install contextify w/o w/o "-g" 时以类似的方式失败 [3],因此这些可能是相关问题.

My attempts to use node-gyp on a Windows 7 + Node.js platform have failed [3] when attempting to compile the standard "Hello World" example [2]. Note: node-gyp is failing in a similar manner [3] when attempting npm install contextify w or w/o the "-g", thus these could be related issues.

配置:

  • 节点-gyp 0.12.2
  • Windows 7 x64 SP1
  • Python 2.7
  • Node.js 0.10.24
  • 每个 [1] 的 Visual Studio 2010(也尝试过 2012)
  • VS SDK 7.1 per [1](尝试了 32 位和 64 位版本)
  • 从标准 Windows 命令提示符或 SDK7.1 cmd 提示符运行 node-gyp

参考:
[1] https://github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup

[2] https://github.com/joyent/node/tree/master/test/addons/hello-world

[3] hello world"[2] 项目上的node-gyp 重建"产生以下 2 个错误:

[3] "node-gyp rebuild" on "hello world"[2] project produces following 2 errors:

....node-gyp\0.10.24\deps\uv\include\win.h(8738): error C2371: 'SYSTEM_POWER_STATUS' : redefinition;不同的基本类型 [...\build\test.vcxproj]

....node-gyp\0.10.24\deps\uv\include\win.h(8738): error C2371: 'SYSTEM_POWER_STATUS' : redefinition; different basic types [...\build\test.vcxproj]

....node-gyp\0.10.24\deps\uv\include\mswsock.h(27): 致命错误 C1083:无法打开包含文件:'_mingw.h':没有这样的文件或目录 [...\build\test.vcxproj]

....node-gyp\0.10.24\deps\uv\include\mswsock.h(27): fatal error C 1083: Cannot open include file: '_mingw.h': No such file or directory [...\build\test.vcxproj]

以及以下 2 个警告:

and following 2 warnings:

....node-gyp\0.10.24\deps\uv\include\win.h(13513):警告 C4005:'UNALIGNED' : 宏重定义 [...\build\test.vcxproj]

....node-gyp\0.10.24\deps\uv\include\win.h(13513): warning C4005: 'UNALIGNED' : macro redefinition [...\build\test.vcxproj]

....node-gyp\0.10.24\deps\uv\include\mswsock.h(26): 警告 C4068: 未知编译指示 [...\build\test.vcxproj]

....node-gyp\0.10.24\deps\uv\include\mswsock.h(26): warning C4068 : unknown pragma [...\build\test.vcxproj]

完整的跟踪如下:

C:\sigma\node_modules\x>node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@0.12.2
gyp info using node@0.10.24 | win32 | x64
gyp info spawn python
gyp info spawn args [ 'C:\\Users\\Anybody\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\sigma\\node_modules\\x\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Anybody\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Anybody\\.node-gyp\\0.10.24\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Anybody\\.node-gyp\\0.10.24',
gyp info spawn args   '-Dmodule_root_dir=C:\\sigma\\node_modules\\x',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\sigma\\node_modules\\x\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn msbuild
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.  test.cpp
C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\win.h(8738): error C2371: 'SYSTEM_POWER_STATUS' : redefinition; different basic types [C:\sigma\node_modules\x\build\test.vcxproj]  C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\win.h(8737) : see declaration of 'SYSTEM_POWER_STATUS'

C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\win.h(13513): warning C4005: 'UNALIGNED' : macro redefinition [C:\sigma\node_modules\x\build\test.vcxproj] C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdef s.h(502) : see previous definition of 'UNALIGNED'

C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\mswsock.h(26): warning C4068 : unknown pragma [C:\sigma\node_modules\x\build\test.vcxproj] C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\_mingw.h(33): warning C4068: unknown pragma [C:\sigma\node_modules\x\build\test.vcxproj]

C:\Users\Anybody\.node-gyp\0.10.24\deps\uv\include\_mingw.h(51): fatal error C1 189: #error :  ERROR: You must use a GNU Compiler. [C:\sigma\node_modules\x\build\test.vcxproj]

gyp ERR! build error
gyp ERR! stack Error: msbuild failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\Anybody\AppData\Roaming\npm\
node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Users\\Anybody\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\sigma\node_modules\x
gyp ERR! node -v v0.10.24
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok   

推荐答案

虽然这个问题是一个多月前的问题,但我最终还是在网上搜索,这是搜索结果的一部分.

Although this question is one month old, i ended up searching across the web and this was part of search results.

所以这是一个不应该做但有效的答案.

So here is a not-should-do-but-it-works answer.

首先,我不熟悉 node-gyp 或整个 Visual Studio 编译和东西,我真的很抱歉依赖于 python 的 node-gyp(一个非常沉默的WTF )

First, i'm not familiar with node-gyp or the whole visual studio compile and stuff, i really really feel sorry for node-gyp depending on python (a really silent WTF )

因此,由于未知原因,nodejs 版本早于 0.10.22(我现在正在运行,所以我假设它从那里开始)

So for no known reason nodejs version older than 0.10.22 (i'm running that now so i assume there it where it starts)

如果您在系统中搜索文件uv.h",您可能会得到一些结果如果您以前安装过 nodejs 版本,否则您可以继续阅读.

If you search your system for the file "uv.h" you might get some results IF you have previously installed nodejs versions, otherwise you could keep reading.

我之前的 0.10.3 nodejs 版本有 uv.h 进入 node-gyp 就像

my previous 0.10.3 nodejs version had uv.h into node-gyp some like

<DRIVERLETTER>:\Users\<USERNAME>\.node-gyp\0.10.3\deps\uv

因此,如果您阅读 npm 文档,您会在 npm install

so if you read the npm documentation you will find the the argument on npm install

--nodedir=/path/to/node/source 参数将允许 npm 找到node 源代码,以便 npm 可以编译本机模块.

The --nodedir=/path/to/node/source argument will allow npm to find the node source code so that npm can compile native modules.

所以最后的命令应该是

npm install <package> --nodedir="<DRIVERLETTER>:\Users\<USERNAME\.node-gyp\0.10.3"

您可能会收到一些警告,但应该会成功完成.

you might get some warnings but it should complete with success.

这篇关于如何让 node-gyp 在 Windows 7 平台上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆