Koromix / koffi

Fast and easy-to-use C FFI module for Node.js
https://koffi.dev/
MIT License
197 stars 3 forks source link

Cannot build koffi on Windows x64 #99

Closed mikeseese closed 1 year ago

mikeseese commented 1 year ago

I am receiving an error when the linker is trying to link abi_x64_win_asm.obj:

MINGW64 /c/work/checkpoint/rygel/src/koffi (master)
$ node ../cnoke/cnoke.js 
>> Using CMake binary: cmake
>> Node: 18.18.0
>> Target: win32_x64
>> Running configuration
Not searching for unused variables given on the command line.
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.34.31937.0
-- The CXX compiler identification is MSVC 19.34.31937.0
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM_MASM compiler identification is MSVC
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/ml64.exe
-- Configuring done (6.6s)
-- Generating done (0.1s)
-- Build files have been written to: C:/work/checkpoint/rygel/src/koffi/build/koffi/win32_x64/v18.18.0_x64
>> Running build
MSBuild version 17.4.1+9a89d02ff for .NET Framework
  1>Checking Build System
  Building Custom Rule C:/work/checkpoint/rygel/src/koffi/CMakeLists.txt
  Assembling C:\work\checkpoint\rygel\src\koffi\src\abi_x64_win_asm.asm...
MASM : warning A4018: invalid command-line option : /Zc:__cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Z:__cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Z__cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Z_cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zcplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zlusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zlus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4200 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4458 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4706 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4100 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4127 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4702 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4201 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4324 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4008: invalid command-line option value, default is used : /W [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
  koffi_unity.c
  koffi_unity.cpp
C:/work/checkpoint/rygel/src/koffi/src/call.cc(1022,26): warning C4456: declaration of 'len' hides previous local declaration [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
C:/work/checkpoint/rygel/src/koffi/src/call.cc(1005,22): message : see declaration of 'len' [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
C:/work/checkpoint/rygel/src/koffi/src/util.cc(1361,22): warning C4457: declaration of 'len' hides function parameter [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
C:/work/checkpoint/rygel/src/koffi/src/util.cc(1263,98): message : see declaration of 'len' [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
C:/work/checkpoint/rygel/src/koffi/src/win32.cc(82,14): warning C4389: '!=': signed/unsigned mismatch [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
C:/work/checkpoint/rygel/src/koffi/../../src/core/libcc/libcc.cc(5753,50): warning C4244: 'argument': conversion from 'RG::Size' to 'int', possible loss of data [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi
.vcxproj]
C:/work/checkpoint/rygel/src/koffi/src/abi_x64_win.cc(198,36): warning C4457: declaration of 'func' hides function parameter [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
C:/work/checkpoint/rygel/src/koffi/src/abi_x64_win.cc(66,44): message : see declaration of 'func' [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
LINK : fatal error LNK1104: cannot open file 'koffi.dir\RelWithDebInfo\abi_x64_win_asm.obj' [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
Error: Failed to run build step
    at Builder.build (C:\work\checkpoint\rygel\src\cnoke\src\builder.js:255:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (C:\work\checkpoint\rygel\src\cnoke\cnoke.js:145:9)

Which is due to the fact the obj file never actually gets generated:

 $ ls build/koffi/win32_x64/v18.18.0_x64/koffi.dir/RelWithDebInfo/
koffi.tlog/  koffi_unity.c.obj  koffi_unity.cpp.obj  vc143.pdb

Running cnoke with --verbose doesn't shed any more information during the assemble step:

_MASM:
  Assembling C:\work\checkpoint\rygel\src\koffi\src\abi_x64_win_asm.asm...
  cmd.exe /C "C:\Users\seese\AppData\Local\Temp\tmp0023abd37691497a93c296f60359c307.cmd"
  ml64.exe /c /nologo /Fo"koffi.dir\RelWithDebInfo\abi_x64_win_asm.obj" /D"WIN32" /D"_WINDOWS" /D"NDEBUG" /D"FELIX_TARGET=koffi" /D"NAPI_DISABLE_CPP_EXCEPTIONS" /D"NAPI_VERSION=8" /D"LIBCC_NO_STATX" /D"_CRT_SECURE_NO_WARNINGS" /D"_CRT_NONSTDC_NO_DEPRECATE" /D" 
  UNITY_BUILD=1" /D"CMAKE_INTDIR="RelWithDebInfo"" /D"koffi_EXPORTS" /I "C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\headers\include\node" /I "C:\work\checkpoint\rygel\src\koffi\." /I "C:\work\checkpoint\rygel\src\koffi\..\.." /I "C:\ 
  work\checkpoint\rygel\src\koffi\..\..\vendor\node-addon-api" /W3 /errorReport:prompt  /Zc:__cplusplus /W4 /wd4200 /wd4458 /wd4706 /wd4100 /wd4127 /wd4702 /wd4201 /wd4324 /TaC:\work\checkpoint\rygel\src\koffi\src\abi_x64_win_asm.asm
MASM : warning A4018: invalid command-line option : /Zc:__cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Z:__cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Z__cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Z_cplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zcplusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zlusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zusplus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zlus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /Zus [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4200 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4458 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4706 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4100 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4127 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4702 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4201 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4018: invalid command-line option : /wd4324 [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
MASM : warning A4008: invalid command-line option value, default is used : /W [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]
ClCompile:
  All outputs are up-to-date.
  All outputs are up-to-date.
Link:
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\koffi.node" /INCREMENTAL /ILK:"koffi.dir\RelWithDebInfo\koffi.ilk" /N 
  OLOGO node.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib Delayimp.lib /DELAYLOAD:node.exe /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG 
   /PDB:"C:/work/checkpoint/rygel/src/koffi/build/koffi/win32_x64/koffi.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/work/checkpoint/rygel/src/koffi/build/koffi/win32_x64/koffi.lib" /MACHINE:X64  /machine:x64 /DLL koffi.dir\RelWithDebInf 
  o\/koffi_unity.c.obj
  koffi.dir\RelWithDebInfo\/koffi_unity.cpp.obj
  koffi.dir\RelWithDebInfo\abi_x64_win_asm.obj
LINK : fatal error LNK1104: cannot open file 'koffi.dir\RelWithDebInfo\abi_x64_win_asm.obj' [C:\work\checkpoint\rygel\src\koffi\build\koffi\win32_x64\v18.18.0_x64\koffi.vcxproj]

Are the "invalid command-line option"s being passed to ml64.exe an issue?

Koromix commented 1 year ago

I just tested and the same happened to me. Not sure why it was not an issue before, this may be caused by a more recent Visual Studio install.

Anyway, I've changed the CMake script to only pass those command-line options to the C++ compiler and not to MASM. This fixes the issue.

Thanks!

mikeseese commented 1 year ago

That also fixed it for me! Thanks a bunch for the quick turnaround!