visual-studiovisual-studio-2013node-gypgyp

How to disable code Optimization with gyp?


I have a gyp generated project that produces the following error in MSVC2013: I have the following error in MSVC2013: error D8016: '/O2' and '/RTC1' command-line options are incompatible.

Therefore I tried to turn off optimizations trying:
'Optimization': 'd', # no message
'Optimization': 'Disabled', # warning message 'AdditionalOptions': ['/Od'] # no message
and none of them works.

How can I set /Od instead of the default /O2 in gyp?


Solution

  • node-gyp loads a common.gypi file with compiler settings before binding.gyp. You can override MSVC settings in your target with a `configuration.Release.msvs_settings.VCCLCompilerTool' dictionary:

      'configuration': { 'Release': { 'msvs_settings': { 'VCCLCompilerTool': {
          'Optimization': 0
      }}}}
    

    See https://github.com/nodejs/node-gyp/issues/26#issuecomment-7296389