在 Visual Studio 2015 中构建 node-gyp 项目时出现 LNK1104 错误

LNK1104 error when building node-gyp project in Visual Studio 2015

我已经尝试了所有方法,我有正确版本的 Python (Python27),安装了 Windows SDK 8.1,也安装了 Visual C++,但是构建仍然失败。我正在使用 Visual Studio 2015 社区编辑器。当我尝试从 cmd 执行 node-gyp build 时,出现以下错误:

> C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.t
argets(44,5): error MSB8020: The builds tools for v140 (Platform Toolset = 'v14
0') cannot be found. To build using the v140 build tools, either click the Proj
ect menu or right-click the solution, and then select "Update VC++ Projects..."
. Install v140 to build using the v140 build tools. [C:\Users\Programming PC\Do
cuments\GitHub\node-addon-examples_hello_world\node_0.10\build\hello.vcxproj]

这个错误提示我进入 Visual Studio 并查看项目是否至少可以构建,然后 运行 从那里构建,但没有。

请帮助我查看了与此问题相关的所有其他问题,但 none 他们的解决方案对我有所帮助。

进行了大量研究,但我找到了解决方案。首先,要消除 MSB8020 错误,请添加 VisualStudioVersion 环境变量并将其设置为您的 visual studio 版本,或者使用此标志 /p:VisualStudioVersion=14.0 执行 node-gyp build (以我为例)。

我在解决这个问题后实际上遇到了不同的错误,我相信它们值得一提。

然后出现

错误MSB4175,基本上是找不到Microsoft.Build.Tasks.v12.0.dll(搜索这个.dll,找出它通常所在的位置),复制并粘贴到路径它正在寻找它。

问题来了,最后一个中断 node-gyp 的错误是因为缺少 .lib 文件。 Npm 不会创建以下文件 ...\.node-gyp.3.1\Debug\node.lib。所以你需要去 here 并下载一个 node.lib 和 mkdir Debug\ 然后把 node.lib 放在那里。

之后 node-gyp 应该没有错误地构建。