Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build on Windows #3

Closed
somanuell opened this issue Sep 27, 2021 · 16 comments
Closed

Can't build on Windows #3

somanuell opened this issue Sep 27, 2021 · 16 comments

Comments

@somanuell
Copy link

somanuell commented Sep 27, 2021

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

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:\xxxxxxx\git\sdk\v2\master\node_modules\irpa_core\node_modules\cpu-feature
s\build\cpufeatures.vcxproj]

@somanuell
Copy link
Author

I think I found the root cause: the node module is compiled with the /MT option (the C/C++ Run Time is to be statically linked)
But the node module 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 C/C++ Run Time. The module build fine after MANUALLY changing /MD to /MT in the Visual Studio projects for the two libraries.

@mscdex
Copy link
Owner

mscdex commented Sep 29, 2021

I don't have access to Windows at the moment. Does this change fix it for you?:

diff --git a/binding.gyp b/binding.gyp
index 58e26fd..0970aa5 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -43,7 +43,7 @@
                   'variables': { 'cmake_arch': 'x64' },
                 }],
               ],
-              'action': [ 'cd <(module_root_dir)/deps/cpu_features/build && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_PIC=ON -A <(cmake_arch) ..' ],
+              'action': [ 'cd <(module_root_dir)/deps/cpu_features/build && cmake -DCMAKE_CXX_FLAGS_RELEASE="/MT" -DCMAKE_BUILD_TYPE=Release -DBUILD_PIC=ON -A <(cmake_arch) ..' ],
             }, { # POSIX
               'outputs': [ '<(module_root_dir)/deps/cpu_features/build/Makefile' ],
               'action': [

@somanuell
Copy link
Author

I juste cloned and patched. What command should I launch in my cmd.exe to trigger the same kind of build that npm install is doing?

@mscdex
Copy link
Owner

mscdex commented Sep 29, 2021

Either npm install (I think) or if you have node-gyp installed globally, node-gyp rebuild.

@somanuell
Copy link
Author

I had to do npm install nan, and after that I could do node-gyp configure and node-gyp build (or rebuild)

But the problem persist, the two libraries project .\deps\cpu_features\build\cpu_features.vcxproj and .\deps\cpu_features\build\utils.vcxproj are still with switch /MD

@somanuell
Copy link
Author

Fof what it's worth, I tried to run the command:
cmake -DCMAKE_CXX_FLAGS_RELEASE="/MT" -DCMAKE_BUILD_TYPE=Release -DBUILD_PIC=ON -A Win32 ..
in .\deps\cpu_features\build and the output was:
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:

CMAKE_CXX_FLAGS_RELEASE

-- Build files have been written to: C:/xxxxxxx/git/cpu-features-source/deps/cpu_features/build

@mscdex
Copy link
Owner

mscdex commented Sep 29, 2021

Huh.... what about -DMSVC_RUNTIME_LIBRARY=MultiThreaded instead ?

@somanuell
Copy link
Author

somanuell commented Sep 29, 2021

Still failing to build, for the same reasons.
Full node-gyp build output with the new MSVC_RUNTIME_LIBRARY=MultiThreaded define:

gyp info it worked if it ends with ok
gyp info using node-gyp@8.2.0
gyp info using node@14.17.6 | win32 | ia32
gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
gyp info spawn args [
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=Win32'
gyp info spawn args ]
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
  Configuring dependencies
  -- Building for: Visual Studio 16 2019
  -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
  -- The C compiler identification is MSVC 19.29.30133.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.3
  0133/bin/Hostx64/x86/cl.exe - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Configuring done
  -- Generating done
CUSTOMBUILD : CMake warning :  [c:\xxxxxxx\git\cpu-features-source\build\config_deps.vcxproj]
  -- Build files have been written to: C:/xxxxxxx/git/cpu-features-source/deps/cpu_features/build
    Manually-specified variables were not used by the project:

      MSVC_RUNTIME_LIBRARY


  Building dependencies
  Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET Framework
  Copyright (C) Microsoft Corporation. All rights reserved.

    Checking Build System
    Building Custom Rule C:/xxxxxxx/git/cpu-features-source/deps/cpu_features/CMakeLists.txt
    filesystem.c
    stack_line_reader.c
    string_view.c
    Generating Code...
    utils.vcxproj -> C:\xxxxxxx\git\cpu-features-source\deps\cpu_features\build\utils.dir\Release\utils.lib
    Building Custom Rule C:/xxxxxxx/git/cpu-features-source/deps/cpu_features/CMakeLists.txt
    cpuinfo_x86.c
    cpu_features.vcxproj -> C:\xxxxxxx\git\cpu-features-source\deps\cpu_features\build\Release\cpu_features.lib
    Building Custom Rule C:/xxxxxxx/git/cpu-features-source/deps/cpu_features/CMakeLists.txt
    list_cpu_features.c
C:\xxxxxxx\git\cpu-features-source\deps\cpu_features\src\utils\list_cpu_features.c(343): warning C4715: 'GetCacheTyp
eString': not all control paths return a value [C:\xxxxxxx\git\cpu-features-source\deps\cpu_features\build\list_cpu_
features.vcxproj] [c:\xxxxxxx\git\cpu-features-source\build\build_deps.vcxproj]
    list_cpu_features.vcxproj -> C:\xxxxxxx\git\cpu-features-source\deps\cpu_features\build\Release\list_cpu_feature
  s.exe
    Building Custom Rule C:/xxxxxxx/git/cpu-features-source/deps/cpu_features/CMakeLists.txt
  binding.cc
  win_delay_load_hook.cc
     Creating library c:\xxxxxxx\git\cpu-features-source\build\Release\cpufeatures.lib and object c:\xxxxxxx\git\
  cpu-features-source\build\Release\cpufeatures.exp
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library [c:\xxxxxxx\
git\cpu-features-source\build\cpufeatures.vcxproj]
MSVCRT.lib(chandler4gs.obj) : error LNK2001: unresolved external symbol __except_handler4_common [c:\xxxxxxx\git\cpu
-features-source\build\cpufeatures.vcxproj]
c:\xxxxxxx\git\cpu-features-source\build\Release\cpufeatures.node : fatal error LNK1120: 1 unresolved externals [c:\
xxxxxxx\git\cpu-features-source\build\cpufeatures.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\I505225\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Windows_NT 10.0.19043
gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Users\\I505225\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
gyp ERR! cwd c:\xxxxxxx\git\cpu-features-source
gyp ERR! node -v v14.17.6
gyp ERR! node-gyp -v v8.2.0
gyp ERR! not ok

@somanuell
Copy link
Author

You could take a look at https://stackoverflow.com/questions/14172856/compile-with-mt-instead-of-md-using-cmake
(I don't know cmake)

@mscdex
Copy link
Owner

mscdex commented Sep 29, 2021

That's where the suggestions I gave came from. I'm not a Cmake expert either.

@somanuell
Copy link
Author

I managed to have cmake generates valid Visual Studio projects for the two libs from deps, that is: with the Code Generation Run Time Library set to Multi threaded (/MT) by running the command:
cmake -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG" -DCMAKE_BUILD_TYPE=Release -DBUILD_PIC=ON -A Win32 ..
in .\deps\cpu_features\build with output:
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/xxxxxxx/git/cpu-features-source6/deps/cpu_features/build
Please not that with this define, I do not have the "Manually-specified variables were not used by the project"

But when I try to patch the binding.gyp file with:

  •          'action': [ 'cd <(module_root_dir)/deps/cpu_features/build && cmake -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG" -DCMAKE_BUILD_TYPE=Release -DBUILD_PIC=ON -A <(cmake_arch) ..' ],
    

and then use node-gyg build I have:
c1 : fatal error C1083: Cannot open source file: '\MT': No such file or directory
SOMEHOW NODE-GYP CHANGE THE SLASH TO AN ANTISLASH!

@mscdex
Copy link
Owner

mscdex commented Sep 30, 2021

Are you using the latest version of node-gyp to rebuild? It seems that this behavior was reverted in node-gyp 8.0.0 with its inclusion of gyp 0.7.0:

msvs: On Windows, arguments passed to the "action" commands are no longer transformed to replace slashes with backslashes.

If you're still encountering this on node-gyp 8.0.0 or newer, you should post an issue about this on their issue tracker here because evidently that shouldn't be happening anymore.

Unfortunately as of this writing, npm hasn't pulled in node-gyp 8.0.0+, so it will be awhile yet before someone can npm install cpu-features and use that particular action command successfully.

@mscdex
Copy link
Owner

mscdex commented Sep 30, 2021

Also, which version of CMake are you using?

@mscdex
Copy link
Owner

mscdex commented Sep 30, 2021

Out of curiosity, what if you use a dash instead of a forward slash, supposedly that is supported by the msvs compiler/linker for their command line arguments as well:

cmake -DCMAKE_C_FLAGS_RELEASE="-MT -O2 -Ob2 -DNDEBUG"

@somanuell
Copy link
Author

node-gyp 8.2.0
CMake 3.21.3

Yes, the dash trick made it!

cpufeatures.vcxproj -> c:\xxxxxxx\git\cpu-features-source7\build\Release\\cpufeatures.node
gyp info ok

Please publish a new version adding -DCMAKE_C_FLAGS_RELEASE="-MT -O2 -Ob2 -DNDEBUG" line 46 of the binding.gyp file.
I will then be able (I hope) to npm install ssh2 (on Windows)

@somanuell
Copy link
Author

Why didn't you bump the version and update on npmjs.com?
(npm install still fails)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants