nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.45k stars 278 forks source link

Node-gyp module fails to build in node v17.0.0 and above but works fine in V16.20.1 #4219

Closed Kam1ni closed 2 months ago

Kam1ni commented 1 year ago

Details

I have a project that relies on some third party C++ closed source libraries that I want to make bindings for in Node.js. It builds fine in Node V16 but starting from V17.0.0 and above (also tested with the latest release of v18 and v20) it fails with a LNK2001 error. But only when I use a few specific functions from that lib. What changed?

The output:

> node-ctep-eik@1.0.0 build
> node-gyp build

gyp info it worked if it ends with ok
gyp info using node-gyp@9.4.0
gyp info using node@17.0.0 | win32 | x64
gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\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=x64'
gyp info spawn args ]
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
  nothing.c
  win_delay_load_hook.cc
  nothing.vcxproj -> C:\Users\kamil\Documents\wf\node-ctep-eik\build\Release\\nothing.lib
cl : command line warning D9025: overriding '/MT' with '/MD' [C:\Users\kamil\Documents\wf\node-ctep-eik\build\ctep-eik-native.vcxproj]
  ctep-service.cc
cl : command line warning D9025: overriding '/MT' with '/MD' [C:\Users\kamil\Documents\wf\node-ctep-eik\build\ctep-eik-native.vcxproj]
  ctep_eik.cc
cl : command line warning D9025: overriding '/MT' with '/MD' [C:\Users\kamil\Documents\wf\node-ctep-eik\build\ctep-eik-native.vcxproj]
  ect-funcs.cc
cl : command line warning D9025: overriding '/MT' with '/MD' [C:\Users\kamil\Documents\wf\node-ctep-eik\build\ctep-eik-native.vcxproj]
  win_delay_load_hook.cc
     Creating library C:\Users\kamil\Documents\wf\node-ctep-eik\build\Release\ctep-eik-native.lib and object C:\Users\kamil\Documents\wf\node-ctep-eik\build\Release\ctep-eik-native.exp
ctep-service.obj : error LNK2001: unresolved external symbol "public: class std::optional<class ect::ECTError> __cdecl ect::SaleResult::error(void)const " (?error@SaleResult@ect@@QEBA?AV?$optional@VECTError@ect@@@std@@XZ) [C:\Users\kamil\Documents\wf\node-ctep-eik\build\ctep-eik-native.vcxproj]
C:\Users\kamil\Documents\wf\node-ctep-eik\build\Release\ctep-eik-native.node : fatal error LNK1120: 1 unresolved externals [C:\Users\kamil\Documents\wf\node-ctep-eik\build\ctep-eik-native.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\kamil\Documents\wf\node-ctep-eik\node_modules\node-gyp\lib\build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\kamil\\Documents\\wf\\node-ctep-eik\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
gyp ERR! cwd C:\Users\kamil\Documents\wf\node-ctep-eik
gyp ERR! node -v v17.0.0
gyp ERR! node-gyp -v v9.4.0
gyp ERR! not ok

Node.js version

This one works

{
  node: '16.20.1',
  v8: '9.4.146.26-node.26',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.19.1',
  modules: '93',
  nghttp2: '1.47.0',
  napi: '8',
  llhttp: '6.0.11',
  openssl: '1.1.1u+quic',
  cldr: '41.0',
  icu: '71.1',
  tz: '2022f',
  unicode: '14.0',
  ngtcp2: '0.8.1',
  nghttp3: '0.7.0'
}

This one and everything above fails

{
  node: '17.0.0',
  v8: '9.5.172.21-node.12',
  uv: '1.42.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.17.2',
  modules: '102',
  nghttp2: '1.45.1',
  napi: '8',
  llhttp: '6.0.4',
  openssl: '3.0.0+quic',
  cldr: '39.0',
  icu: '69.1',
  tz: '2021a',
  unicode: '13.0',
  ngtcp2: '0.1.0-DEV',
  nghttp3: '0.1.0-DEV'
}

Example code

My bindings.gyp

{
    'targets': [
        {
            'target_name': 'ctep-eik-native',
            'sources': [ 
                "<!@(node -p \"require('fs').readdirSync('./src').map(f=>'src/'+f).filter(f=>f.endsWith('.cc')).join('\ ')\")" 
            ],
            'include_dirs': [
                "<!@(node -p \"require('node-addon-api').include\")",
                "./dependencies/ctep-eik/include"
            ],
            'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
            'cflags!': [ '-fno-exceptions' ],
            'cflags_cc!': [ '-fno-exceptions' ],
            'xcode_settings': {
                'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
                'CLANG_CXX_LIBRARY': 'libc++',
                'MACOSX_DEPLOYMENT_TARGET': '10.7'
            },
            'msvs_settings': {
                'VCCLCompilerTool': { 
                    'ExceptionHandling': 1,
                    'AdditionalOptions':[
                        '/MD'
                    ]
                },
                'VCLinkerTool': {
                    'AdditionalOptions': [ '/NODEFAULTLIB:library' ],
                },
            },
            'conditions':[
                ['OS=="win"', {
                    "libraries":[
                        "-l<(module_root_dir)/dependencies/ctep-eik/lib/windows/64bit/easyctepcpp.lib",
                        "-l<(module_root_dir)/dependencies/ctep-eik/lib/windows/64bit/easyctep.lib",
                    ],
                    "copies":[
                        {
                            "destination":"./build/Release",
                            "files":[
                                "./dependencies/ctep-eik/lib/windows/64bit/easyctep.dll",
                                "./dependencies/ctep-eik/lib/windows/64bit/Qt5CoreEik.dll",
                                "./dependencies/ctep-eik/lib/windows/64bit/Qt5NetworkEik.dll",
                                "./dependencies/ctep-eik/lib/windows/64bit/Qt5SerialPortEik.dll",
                            ]
                        }
                    ]
                }]
            ]
        }
    ]
}

Operating system

Microsoft Windows [Version 10.0.19045.3208]

Scope

issue with node-gyp build

Module and version

Not applicable.

preveen-stack commented 1 year ago

cc @nodejs/gyp

github-actions[bot] commented 3 months ago

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] commented 2 months ago

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.