node-gyp icon indicating copy to clipboard operation
node-gyp copied to clipboard

[solved] Using Visual C++ Build Tools 2015 – standalone C++ tools

Open dotnetCarpenter opened this issue 11 years ago • 78 comments

[EDIT]

Guide

1 Your OS MUST be Windows 2 Check that python is in your path by writting python --version in the console. If not then 2.1 Download python 2.7 (I recommend chocolatey (choco install python2 -y)) 3. Are you on Windows 7? Then follow the rest of 3.x 3.1 Check that you have .NET 4.5.1+ installed. If not then 3.2 Download and install .NET 4.5.1 (.NET 4.5.2 will also work just fine) 4 Download Microsoft Visual C++ Build Tools 2015 Technical Preview 4.1 Install the Windows 8.1 SDK if you haven't already. Note; I recently updated to Windows 10 and had to install the Windows 10 SDK before node-gyp would successfully build. 5 Set the npm config variable msvs_version to 2015: npm config -g set msvs_version 2015 6 Do npm i in what-ever project with node-gyp as a dependency without seeing weird error messages :+1:

Tested with node 5.0.0+ and npm 3.3.6

thanks to @mousetraps

I happily noticed that MS provides a standalone c++ compiler. I will try to use it with node-gyp (via utf-8-validate) and report my findings here.

http://blogs.msdn.com/b/vcblog/archive/2015/11/02/announcing-visual-c-build-tools-2015-standalone-c-tools-for-build-environments.aspx

dotnetCarpenter avatar Nov 06 '15 12:11 dotnetCarpenter

Adding C:\Program Files (x86)\MSBuild\14.0\Bin to my PATH yields no result. Still getting:

MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location o f the component to the system path if it is installed elsewhere.  [C:\Users\dotnet\Projects\firefund-cli\node_modules\utf-8-validate\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `msbuild` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\dotnet\Projects\firefund-cli\node_modules\utf-8-validate
gyp ERR! node -v v5.0.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm WARN install:utf-8-validate [email protected] install: `node-gyp rebuild`
npm WARN install:utf-8-validate Exit status 1

Need to tell node-gyp to use MSBuild.exe

dotnetCarpenter avatar Nov 06 '15 14:11 dotnetCarpenter

@dotnetCarpenter hey, thanks for trying it out! Did you end up getting it working? Is there anything missing from these steps? https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245

mousetraps avatar Nov 10 '15 22:11 mousetraps

thx @mousetraps. Unfortunately I'm not sure how to tell node-gyp to use MSBuild.exe.

You comment prompted me to try just compiling a project via npm install. I've set npm config set msvs_version 2015 --global but didn't set python as python --version already gives me 2.7.10.

I saw that you successfully compiled utf-8-validate so I cloned that repo and did npm i. The result was not very encouraging: c:\users\dotnet\.node-gyp\5.0.0\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [C:\Users\dotnet\Projects\playground\utf-8-validate\b uild\validation.vcxproj]

Got .Net 4.5.2 : Release DWORD 5cbf5 (379893)

Entire output:

> [email protected] install C:\Users\dotnet\Projects\playground\utf-8-validate
> node-gyp rebuild


C:\Users\dotnet\Projects\playground\utf-8-validate {git}
{lamb} if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or Platfo rmToolset may be set to an invalid version number. [C:\Users\dotnet\Projects\playground\utf-8-validate\build\validation.vcxproj]
  validation.cc
c:\users\dotnet\.node-gyp\5.0.0\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [C:\Users\dotnet\Projects\playground\utf-8-validate\b uild\validation.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\dotnet\Projects\playground\utf-8-validate
gyp ERR! node -v v5.0.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i"
npm ERR! node v5.0.0
npm ERR! npm  v3.3.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the utf-8-validate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls utf-8-validate
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\dotnet\Projects\playground\utf-8-validate\npm-debug.log

dotnetCarpenter avatar Nov 11 '15 19:11 dotnetCarpenter

Did you install the Windows sdk too when installing the build tools (this should be the default)? I believe that's where winsock2.h comes from.

mousetraps avatar Nov 11 '15 19:11 mousetraps

I get a similar errors when building ws.

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or Platfo rmToolset may be set to an invalid version number. [C:\Users\dotnet\Projects\playground\ws\node_modules\bufferutil\build\bufferutil.vcxproj]
  bufferutil.cc
c:\users\dotnet\.node-gyp\5.0.0\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [C:\Users\dotnet\Projects\playground\ws\node_modules\ bufferutil\build\bufferutil.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or Platfo rmToolset may be set to an invalid version number. [C:\Users\dotnet\Projects\playground\ws\node_modules\utf-8-validate\build\validation.vcxproj]
  validation.cc
c:\users\dotnet\.node-gyp\5.0.0\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [C:\Users\dotnet\Projects\playground\ws\node_modules\ utf-8-validate\build\validation.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)

dotnetCarpenter avatar Nov 11 '15 19:11 dotnetCarpenter

@dotnetcarpenter Even after installing the Windows sdk?

mousetraps avatar Nov 11 '15 20:11 mousetraps

Should I install the Windows 8.1 SDK with the Build Tools installer or the Windows 7 SDK when I'm on Windows 7?

Unfortunately I can not update to Windows 10 due to an unknown installation error when upgrading.

dotnetCarpenter avatar Nov 12 '15 12:11 dotnetCarpenter

Hmm.. I somehow thought I could get things compiling without a Windows SDK but in the end I installed Windows 8.1 SDK via the installer and things seems to be working. :tada:

OS: Windows7 Node: 5.0.0 Npm: 3.3.6

dotnetCarpenter avatar Nov 12 '15 17:11 dotnetCarpenter

@dotnetCarpenter Hi. Installed the Build Tools 2015 provided by @mousetraps, followed instructions, tried to install selenium-webdriver (node-gyp dependant) and got the error below. Any ideas? (nodejs 4.2.2, npm 3.4, windows 10x64) Thank you!

C:\Users\rickm\AppData\Roaming\npm\node_modules\selenium-webdriver\node_modules\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Users\rickm\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node rebuild ) Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not fi nd WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid versio n number. [C:\Users\rickm\AppData\Roaming\npm\node_modules\selenium-webdriver\node_modules\utf-8-validate\build\validat ion.vcxproj] validation.cc c:\users\rickm.node-gyp\4.2.2\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [C:\Users\rickm\AppData\Roaming\npm\node_modules\selenium-webdriver\node_modules\utf-8-validate \build\validation.vcxproj] gyp ERR! build error gyp ERR! stack Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Users\rickm\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23) gyp ERR! stack at emitTwo (events.js:87:13) gyp ERR! stack at ChildProcess.emit (events.js:172:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12) gyp ERR! System Windows_NT 10.0.10240 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\rickm\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\rickm\AppData\Roaming\npm\node_modules\selenium-webdriver\node_modules\utf-8-validate gyp ERR! node -v v4.2.2 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok npm WARN install:[email protected] [email protected] install: node-gyp rebuild npm WARN install:[email protected] Exit status 1

rickmed avatar Nov 15 '15 04:11 rickmed

warning MSB8003: Could not find WindowsSDKDir variable from the registry.

Looks like you're missing the Windows 10 SDK, since you are on Windows 10. I think you can uninstall Windows SDK 8.1. Let me know if it works and I'll update the guide to be more clear.

Also, be sure to: 3.1 Check that you have .NET 4.5.1+ installed. If not then 3.2 Download and install .NET 4.5.1 (.NET 4.5.2 will also work just fine)

dotnetCarpenter avatar Nov 15 '15 15:11 dotnetCarpenter

I have installed the windows 10 SDKs but somehow I think it failed to add it to the registry (or something like that), but I don't know how to fix it...

rickmed avatar Nov 15 '15 18:11 rickmed

Run the VisualCppBuildTools_Full.exe that you downloaded from https://www.microsoft.com/en-us/download/details.aspx?id=49512 and choose Repair.

dotnetCarpenter avatar Nov 15 '15 18:11 dotnetCarpenter

@dotnetCarpenter I finally got it working checking BOTH windows 10 SDKs and windows 8 SDK (I'm on win10) when installing the 2015 build tools. It seems that somehow the windows 10 SDKs is built on top of the windows 8 SDKs OR the windows 10 SDKs package has a bug that fails to add the correspondent registry values, and my system is simple using the windows 8 SDKs (when I added it later).

rickmed avatar Nov 19 '15 15:11 rickmed

sounds weird. perhaps @mousetraps has an idea to why.

dotnetCarpenter avatar Nov 21 '15 01:11 dotnetCarpenter

@dotnetCarpenter - I followed your Guide above with a clean install of Windows 10. The only correction I would make is that, while the Windows 8.1 SDK must be installed, the Windows 10 SDK is completely unnecessary (at least for the purpose of this issue).

LittleBrainz avatar Nov 30 '15 14:11 LittleBrainz

@LittleBrainz thanks. I will update the guide. @mousetraps I noticed that the link to Microsoft Visual C++ Build Tools 2015 Technical Preview doesn't work anymore. Is the correct link now Microsoft Build Tools 2015 ?

dotnetCarpenter avatar Dec 01 '15 17:12 dotnetCarpenter

@mousetraps I can't find the link to Microsoft Visual C++ Build Tools 2015. It seems that you're out of Technical Preview but there is no updates on the C++ blog

dotnetCarpenter avatar Dec 01 '15 17:12 dotnetCarpenter

@dotnetCarpenter Link was fixed on the C++ blog: Download Visual C++ Build Tools 2015

HoriLiu avatar Dec 02 '15 08:12 HoriLiu

@HoriLiu thanks! updated

dotnetCarpenter avatar Dec 02 '15 10:12 dotnetCarpenter

Apparently, it doesn't matter what OS you're on. You just need the Windows 8.1 SDK.

@mousetraps I suspect that the Windows SDK prerequisite, is node add-on dependent. So if add-on A uses some feature of Windows 10 SDK, then we must install the Windows 10 SDK, correct?

dotnetCarpenter avatar Dec 02 '15 10:12 dotnetCarpenter