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

Update documentation for RuntimeLibrary [help required] (was: How do I set the RuntimeLibrary to /MT (MT_StaticRelease)?) #1686

Closed
iffy opened this issue Mar 5, 2019 · 7 comments

Comments

@iffy
Copy link

iffy commented Mar 5, 2019

  • Node Version: v11.8.0
  • NPM Version: 6.5.0
  • Platform: Microsoft Windows 10 Enterprise Evaluation / 10.0.15063 N/A Build 15063 / x64-base PC
  • Compiler: Microsoft (R) Build Engine version 14.0.25420.1
    Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86
  • Module: My own
Verbose output (from npm or node-gyp):
gyp info it worked if it ends with ok
gyp verb cli [ 'C:\\Program Files (x86)\\nodejs\\node.exe',
gyp verb cli   'C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'clean',
gyp verb cli   'configure',
gyp verb cli   'rebuild',
gyp verb cli   '--arch=ia32',
gyp verb cli   '--verbose' ]
gyp info using node-gyp@3.8.0
gyp info using node@11.8.0 | win32 | ia32
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "C:\Users\IEUser\.windows-build-tools\python27\python.exe" in the PATH
gyp verb `which` succeeded C:\Users\IEUser\.windows-build-tools\python27\python.exe C:\Users\IEUser\.windows-build-tools\python27\python.exe
gyp verb check python version `C:\Users\IEUser\.windows-build-tools\python27\python.exe -c "import sys; print "2.7.15
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 11.8.0
gyp verb command install [ '11.8.0' ]
gyp verb install input version string "11.8.0"
gyp verb install installing version: 11.8.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 11.8.0
gyp verb build dir attempting to create "build" dir: C:\proj\nodebuckets\build
gyp verb build dir "build" dir needed to be created? C:\proj\nodebuckets\build
gyp verb Not using VS2017: Could not use PowerShell to find VS2017
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: C:\proj\nodebuckets\build\config.gypi
gyp verb config.gypi checking for gypi file: C:\proj\nodebuckets\config.gypi
gyp verb common.gypi checking for gypi file: C:\proj\nodebuckets\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn C:\Users\IEUser\.windows-build-tools\python27\python.exe
gyp info spawn args [ 'C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\proj\\nodebuckets\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\IEUser\\.node-gyp\\11.8.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\IEUser\\.node-gyp\\11.8.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\Users\\IEUser\\.node-gyp\\11.8.0\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\proj\\nodebuckets',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\proj\\nodebuckets\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "C:\Users\IEUser\.windows-build-tools\python27\python.exe" in the PATH
gyp verb `which` succeeded C:\Users\IEUser\.windows-build-tools\python27\python.exe C:\Users\IEUser\.windows-build-tools\python27\python.exe
gyp verb check python version `C:\Users\IEUser\.windows-build-tools\python27\python.exe -c "import sys; print "2.7.15
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 11.8.0
gyp verb command install [ '11.8.0' ]
gyp verb install input version string "11.8.0"
gyp verb install installing version: 11.8.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 11.8.0
gyp verb build dir attempting to create "build" dir: C:\proj\nodebuckets\build
gyp verb build dir "build" dir needed to be created? C:\proj\nodebuckets\build
gyp verb Not using VS2017: Could not use PowerShell to find VS2017
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: C:\proj\nodebuckets\build\config.gypi
gyp verb config.gypi checking for gypi file: C:\proj\nodebuckets\config.gypi
gyp verb common.gypi checking for gypi file: C:\proj\nodebuckets\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn C:\Users\IEUser\.windows-build-tools\python27\python.exe
gyp info spawn args [ 'C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\proj\\nodebuckets\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\IEUser\\.node-gyp\\11.8.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\IEUser\\.node-gyp\\11.8.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\Users\\IEUser\\.node-gyp\\11.8.0\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\proj\\nodebuckets',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\proj\\nodebuckets\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture ia32
gyp verb node dev dir C:\Users\IEUser\.node-gyp\11.8.0
gyp verb found first Solution file build/binding.sln
gyp verb `which` succeeded for `msbuild` C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.EXE
gyp info spawn msbuild
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=Win32' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 3/4/2019 9:15:36 PM.
Project "C:\proj\nodebuckets\build\binding.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Win32".
Project "C:\proj\nodebuckets\build\binding.sln" (1) is building "C:\proj\nodebuckets\build\action_after_build.vcxproj.metaproj" (2) on node 1 (default targets).
Project "C:\proj\nodebuckets\build\action_after_build.vcxproj.metaproj" (2) is building "C:\proj\nodebuckets\build\bucketslib.vcxproj.metaproj" (3) on node 1 (default targets).
Project "C:\proj\nodebuckets\build\bucketslib.vcxproj.metaproj" (3) is building "C:\proj\nodebuckets\node_modules\node-addon-api\src\nothing.vcxproj" (4) on node 1 (default targets).
PrepareForBuild:
  Creating directory "C:\proj\nodebuckets\build\Release\".
InitializeBuildStatus:
  Creating "Release\obj\nothing\nothing.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  All outputs are up-to-date.
  All outputs are up-to-date.
Lib:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\Lib.exe /OUT:"C:\proj\nodebuckets\build\Release\nothing.lib" /NOLOGO /LTCG:INCREMENTAL Release\obj\nothing\nothing.obj
  Release\obj\nothing\win_delay_load_hook.obj
  nothing.vcxproj -> C:\proj\nodebuckets\build\Release\\nothing.lib
FinalizeBuildStatus:
  Deleting file "Release\obj\nothing\nothing.tlog\unsuccessfulbuild".
  Touching "Release\obj\nothing\nothing.tlog\nothing.lastbuildstate".
Done Building Project "C:\proj\nodebuckets\node_modules\node-addon-api\src\nothing.vcxproj" (default targets).
Project "C:\proj\nodebuckets\build\bucketslib.vcxproj.metaproj" (3) is building "C:\proj\nodebuckets\build\bucketslib.vcxproj" (5) on node 1 (default targets).
PrepareForBuild:
  Creating directory "Release\obj\bucketslib\".
  Creating directory "Release\obj\bucketslib\bucketslib.tlog\".
InitializeBuildStatus:
  Creating "Release\obj\bucketslib\bucketslib.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\CL.exe /c /I"C:\Users\IEUser\.node-gyp\11.8.0\include\node" /I"C:\Users\IEUser\.node-gyp\11.8.0\src" /I"C:\Users\IEUser\.node-gyp\11.8.0\deps\openssl\config" /I"C:\Users\IEUser\.node-gyp\11.8.0\deps\openssl\openssl\include" /I"C:\Users\IEUser\.node-gyp\11.8.0\deps\uv\include" /I"C:\Users\IEUser\.node-gyp\11.8.0\deps\zlib" /I"C:\Users\IEUser\.node-gyp\11.8.0\deps\v8\include" /I"C:\proj\nodebuckets\node_modules\node-addon-api" /IC:\proj\nodebuckets\inc /IC:\proj\nodebuckets\csrc32 /Zi /nologo /W1 /WX- /O2 /Oy- /D NODE_GYP_MODULE_NAME=bucketslib /D USING_UV_SHARED=1 /D USING_V8_SHARED=1 /D V8_DEPRECATION_WARNINGS=1 /D WIN32 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _HAS_EXCEPTIONS=0 /D BUILDING_NODE_EXTENSION /D _WINDLL /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Release\obj\bucketslib\\" /Fd"Release\obj\bucketslib\vc140.pdb" /Gd /TP /wd4351 /wd4355 /wd4800 /wd4251 /wd4275 /wd4244 /wd4267 /analyze- /errorReport:queue ..\jstonimbinding.cpp "C:\Users\IEUser\AppData\Roaming\npm\node_modules\node-gyp\src\win_delay_load_hook.cc"
  jstonimbinding.cpp
  win_delay_load_hook.cc
  Generating Code...
Link:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\link.exe /ERRORREPORT:QUEUE /OUT:"C:\proj\nodebuckets\build\Release\bucketslib.node" /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib DelayImp.lib "C:\Users\IEUser\.node-gyp\11.8.0\ia32\node.lib" C:\proj\nodebuckets\clib\win\buckets32.dll /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\proj\nodebuckets\build\Release\bucketslib.pdb" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /SAFESEH:NO /DLL Release\obj\bucketslib\jstonimbinding.obj
  Release\obj\bucketslib\win_delay_load_hook.obj
  C:\proj\nodebuckets\build\Release\nothing.lib
buckets32.dll(buckets_clib.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_system.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(buckets_db.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_db_sqlite.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_tables.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_strutils.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_os.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_parsejson.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
buckets32.dll(stdlib_parseutils.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
     Creating library C:\proj\nodebuckets\build\Release\bucketslib.lib and object C:\proj\nodebuckets\build\Release\bucketslib.exp
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [C:\proj\nodebuckets\build\bucketslib.vcxproj]
C:\proj\nodebuckets\build\Release\bucketslib.node : fatal error LNK1319: 9 mismatches detected [C:\proj\nodebuckets\build\bucketslib.vcxproj]
Done Building Project "C:\proj\nodebuckets\build\bucketslib.vcxproj" (default targets) -- FAILED.
Done Building Project "C:\proj\nodebuckets\build\bucketslib.vcxproj.metaproj" (default targets) -- FAILED.
Done Building Project "C:\proj\nodebuckets\build\action_after_build.vcxproj.metaproj" (default targets) -- FAILED.
Done Building Project "C:\proj\nodebuckets\build\binding.sln" (default targets) -- FAILED.

Build FAILED.

"C:\proj\nodebuckets\build\binding.sln" (default target) (1) ->
"C:\proj\nodebuckets\build\action_after_build.vcxproj.metaproj" (default target) (2) ->
"C:\proj\nodebuckets\build\bucketslib.vcxproj.metaproj" (default target) (3) ->
"C:\proj\nodebuckets\build\bucketslib.vcxproj" (default target) (5) ->
(Link target) -> 
  LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [C:\proj\nodebuckets\build\bucketslib.vcxproj]


"C:\proj\nodebuckets\build\binding.sln" (default target) (1) ->
"C:\proj\nodebuckets\build\action_after_build.vcxproj.metaproj" (default target) (2) ->
"C:\proj\nodebuckets\build\bucketslib.vcxproj.metaproj" (default target) (3) ->
"C:\proj\nodebuckets\build\bucketslib.vcxproj" (default target) (5) ->
(Link target) -> 
  buckets32.dll(buckets_clib.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_system.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(buckets_db.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_db_sqlite.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_tables.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_strutils.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_os.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_parsejson.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  buckets32.dll(stdlib_parseutils.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj [C:\proj\nodebuckets\build\bucketslib.vcxproj]
  C:\proj\nodebuckets\build\Release\bucketslib.node : fatal error LNK1319: 9 mismatches detected [C:\proj\nodebuckets\build\bucketslib.vcxproj]

    1 Warning(s)
    10 Error(s)

Time Elapsed 00:00:02.50
gyp ERR! build error 
gyp ERR! stack Error: `msbuild` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\IEUser\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:197:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Users\\IEUser\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "clean" "configure" "rebuild" "--arch=ia32" "--verbose"
gyp ERR! cwd C:\proj\nodebuckets
gyp ERR! node -v v11.8.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

I'm trying to compile my own native add-on. I'm trying to link against a static library. On macOS and Linux it works fine, but on Windows, I'm getting this error:

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in jstonimbinding.obj

When I search the Internet, it seems like everyone else's versions of this error has MT_StaticRelease and MD_DynamicRelease switched. That is, it seems like the default for everyone else is MT_StaticRelease but for me it's MD_DynamicRelease.

  1. Why is mine building with MD_DynamicRelease and how can I make it instead build with MT_StaticRelease?
  2. Does Electron default to MD_DynamicRelease, so once I fix this error am I going to have the opposite problem with Electron?

build/config.gypi includes "node_shared": "false", But you can see from the verbose build output that CL.exe is being called with /MD rather than /MT. I've tried all kinds of variations of msvs_settings.VCCLCompilerTool.RuntimeLibrary but it seems to have no effect.

As a side question, what would it take to remove node's dependence on GYP? Is a pure-JavaScript build system possible? Or is that a chicken-and-egg problem that can't be solved?

binding.gyp
{
  "targets": [
    {
      "target_name": "bucketslib",
      "sources": [
        "jstonimbinding.cpp",
      ],
      "include_dirs": [
          "<!@(node -p \"require('node-addon-api').include\")",
          "<(module_root_dir)/inc",
      ],
      "conditions": [
        [
          'OS=="win" and target_arch == "ia32"',
          {
            "link_settings": {
              'libraries': [
                "<(module_root_dir)/clib/<(OS)/buckets32.dll"
              ],
            },
            "include_dirs": [
              "<(module_root_dir)/csrc32",
            ],
            'cflags_cc': [ "-fPIC" ],
          },
          'OS=="win" and target_arch == "x64"',
          {
            "link_settings": {
              'libraries': [
                "<(module_root_dir)/clib/<(OS)/buckets64.dll"
              ],
            },
            "include_dirs": [
              "<(module_root_dir)/csrc64",
            ],
            'cflags_cc': [ "-fPIC" ],
          },
          {
            "link_settings": {
              'libraries': [
                "<(module_root_dir)/clib/<(OS)/libbuckets.a"
              ],
            },
            "include_dirs": [
              "<(module_root_dir)/csrc",
            ],
          },
        ]
      ],
      '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',
      },
      "msbuild_settings": {
        "Link": {
          "ImageHasSafeExceptionHandlers": "false"
        }
      },
    },
    {
      "target_name": "action_after_build",
      "type": "none",
      "dependencies": ["bucketslib"],
      "copies": [
        {
          "files": ["<(PRODUCT_DIR)/bucketslib.node"],
          "destination": "<(module_root_dir)/lib/<(target_arch)/",
        }
      ]
    }
  ]
}
@sdasun
Copy link

sdasun commented Apr 15, 2019

Did you find a solution? I'm facing the same issue. :/

@iffy
Copy link
Author

iffy commented Apr 15, 2019

@sdasun no I never figured it out. I ended up not linking against a static library (which I was building) and instead just have node-gyp do the compiling of my source.

@sdasun
Copy link

sdasun commented Apr 15, 2019 via email

@sdasun
Copy link

sdasun commented Apr 16, 2019

@iffy It turned out that my library actually was MD though I've given a compiler directive on the configuration file. Forcing to add /MT modifier to the compiler did the trick. At least for my case.

@refack
Copy link
Contributor

refack commented Apr 16, 2019

Help in documenting this will be appreciated.

This is the snippet needed in your binding.gyp

  'msvs_settings': {
    'VCLinkerTool': {
      'AdditionalOptions': [ '/NODEFAULTLIB:library' ],
    },
  },

Because RuntimeLibrary is inherited from node-core's common.gypi through 'target_defaults': { 'configurations': {
Refs: https://github.com/nodejs/node/blob/f85ef977e6e9f0f655a8ff6aa4796d80ae94010e/common.gypi#L116-L126
and https://github.com/nodejs/node/blob/f85ef977e6e9f0f655a8ff6aa4796d80ae94010e/common.gypi#L155-L168
In order to change that, the needed snippet is a little verbose:

{
  'target_defaults': {
    'configurations': {
      'Debug': {
        'msvs_settings': {
          'VCCLCompilerTool': {
            # 0 - MultiThreaded (/MT)
            # 1 - MultiThreadedDebug (/MTd)
            # 2 - MultiThreadedDLL (/MD)
            # 3 - MultiThreadedDebugDLL (/MDd)
            'RuntimeLibrary': 1,
          }
        }
      },
      'Release': {
        'msvs_settings': {
          'VCCLCompilerTool': {
            'RuntimeLibrary': 0,  # shared release
          },
        },
      },
    },
  },
}

@rvagg rvagg changed the title How do I set the RuntimeLibrary to /MT (MT_StaticRelease)? Update documentation for RuntimeLibrary [help required] (was: How do I set the RuntimeLibrary to /MT (MT_StaticRelease)?) Jun 21, 2019
@bnoordhuis
Copy link
Member

bnoordhuis commented Apr 28, 2020

I'm going to close this because it's been inactive for a long time and because it's not a really a node-gyp issue (as in: it's not a node-gyp bug report, it's a question of how do I do something with node-gyp - nodejs/help is a more appropriate place for that.)

Having said all that, mixing CRTs is almost never what you want to do, that's a recipe for disaster. For example, you can't free() a pointer that was malloc'd from the other CRT.

@mmomtchev
Copy link

@bnoordhuis, @refack in fact, when using /MT[d], every DLL (ie Node addon) will have its own heap - distinct from the one used by Node itself.
This is seems to be a weird decision, is there a reason for it?

Nan, which is mostly C++ templates will use the same heap as the module, but when allocating Buffers - which might be allocated in the module and freed in Node - one is bound to run into trouble - and this is precisely what happens in my case.

What is even more surprising is that when using the debug version (/MTd) it will fail with an assert in debug_heap.cpp:996, but the release version won't complain? Does this mean that every time someone uses Nan::NewBuffer this leads to the buffer leaking on Windows? Does it also mean that a properly written Node addon is to always modify this setting?

(look at this discussion: https://docs.microsoft.com/en-us/answers/questions/240332/assert-when-using-mtd-dynamic-library.html)

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

5 participants