How to npm i ssh2 without errors on Windows?

Viewed 784

npm i ssh2 ends with:

MSVCRT.lib(chandler4gs.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4 [c:\xxxxxxx\git\sdk\v2\master\node_modules\yyyy\node_modules\cpu-features\build\cpufeatures. vcxproj] c:\xxxxxxx\git\sdk\v2\master\node_modules\yyyy\node_modules\cpu-features\build\Release\cpufeatures.node : fatal error LNK1120: 1 unresolved externals [c:\SAPDevelop\git\sdk\v2\master\node_modules\irpa_core\node_modules\cpu-feature s\build\cpufeatures.vcxproj]

As you can see, the problem is in cpu-features. I was able to look at the cpu-features build files for MS Visual Studio (by running npm i cpu-features) and I think I found the root cause: the node module (cpufeatures.node) is compiled with the /MT option (the C/C++ Run Time is to be statically linked) But the DLL is linked to cpu_features.lib, witch is itself built with a link to utils.lib... The two libraries, cpu_features.lib and utils.lib are compiled with the /MD switch (C/C++ Run Time is to be dynamicaly linked)

That's not correct. On Windows with Visual Studio, all libs linked to a DLL must use the same option with respect to link to the C/C++ Run Time. The DLL cpufeatures.node build fine after MANUALLY changing /MD to /MT in the Visual Studio projects for the two libraries.

I know nothing about cmake.

Question: how to successfully npm install ssh2 on Windows?

(I created an issue here: https://github.com/mscdex/cpu-features/issues/3 with no avail so far. I understand that cpu-features is optional for ssh2. Alternative question: how to tell npm install ssh2 to not try to build cpu-features?)

 Windows 10 Enterprise 64 bits 21H1 build 19043.1237
 node v14.17.6
 npm 6.14.15
 node-gyp 8.2.0
 cmake 3.21.3
 Visual Studio Enterprise 2019 Version 16.11.3
1 Answers

Answer to the alternative question:

npm install nan
npm install ssh2 --no-optional
Related