node-gyp: error: exception handling disabled, use -fexceptions to enable

I’m trying to update zeromq.node to use gyp as part of the process of getting it running on Windows (JustinTulloss/zeromq.node#81). I’m currently blocked by gyp’s -fno-exceptions default (I think), but will probably run into linking issues soon enough.

Here’s binding.gyp:

{
  'targets': [
    {
      'target_name': 'binding',
      'sources': [ 'binding.cc' ],
      'cflags': ['-fexceptions'],
      'cflags_cc': ['-fexceptions']
    }
  ]
}

Here’s a transcript:

seth@lotus:~/src/JustinTulloss/zeromq.node [⚡ gyp] $ node-gyp configure --target=0.7
info it worked if it ends with ok 
spawn python [ '/Users/seth/.node-gyp/0.7/tools/gyp_addon',
  '-f',
  'make',
  '--suffix',
  '.gyp',
  '-I',
  '/Users/seth/.node-gyp/0.7/tools/patch2722.gypi',
  '-Dtarget_arch=x64' ]
info done ok 
seth@lotus:~/src/JustinTulloss/zeromq.node [⚡ gyp] $ node-gyp build
info it worked if it ends with ok 
spawn make [ 'BUILDTYPE=Release', '-f', 'Makefile.gyp' ]
  CXX(target) out/Release/obj.target/binding/binding.o
binding.cc: In constructor ‘zmq::Context::Context(int)’:
binding.cc:185: error: exception handling disabled, use -fexceptions to enable
make: *** [out/Release/obj.target/binding/binding.o] Error 1
ERR! `make` failed with exit code: 2
ERR! not ok

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@mojodna Ok so I just confirmed that this indeed enables C++ exceptions:

{
  'targets': [
    {
      'target_name': 'bindings',
      'sources': [ 'bindings.cc' ],
      'cflags!': [ '-fno-exceptions' ],
      'cflags_cc!': [ '-fno-exceptions' ],
      'conditions': [
        ['OS=="mac"', {
          'xcode_settings': {
            'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
          }
        }]
      ]
    }
  ]
}

I’m gonna close, reopen if you’re still having troubles.

Here it is a more comprehensive list of flags to enable exceptions on all platforms builds:

{
"conditions": [
          [ "OS=='linux'", {
              "cflags+": [ "-std=c++11", "-fexceptions" ],
              "cflags_c+": [ "-std=c++11", "-fexceptions" ],
              "cflags_cc+": [ "-std=c++11", "-fexceptions" ],
          }],
          [ "OS=='freebsd'", {
              "cflags+": [ "-std=c++11", "-fexceptions" ],
              "cflags_c+": [ "-std=c++11", "-fexceptions" ],
              "cflags_cc+": [ "-std=c++11", "-fexceptions" ],
          }],
          [ "OS=='mac'", {
              "cflags+": [ "-stdlib=libc++" ],
              "xcode_settings": {
                  "OTHER_CPLUSPLUSFLAGS" : [ "-std=c++11", "-stdlib=libc++", "-pthread" ],
                  "OTHER_LDFLAGS": [ "-stdlib=libc++" ],
                  "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
                  "MACOSX_DEPLOYMENT_TARGET": "10.7",
                  "CLANG_CXX_LANGUAGE_STANDARD":"c++11",
                  "CLANG_CXX_LIBRARY": "libc++"
              },
          }],
          [
          "OS=='win'", {
            "cflags": [
              "-Wall"
            ],
            "defines": [
              "WIN"
            ],
            "msvs_settings": {
              "VCCLCompilerTool": {
                "ExceptionHandling": "2",
                "DisableSpecificWarnings": [
                  "4244"
                ],
              },
              "VCLinkerTool": {
                "LinkTimeCodeGeneration": 1,
                "OptimizeReferences": 2,
                "EnableCOMDATFolding": 2,
                "LinkIncremental": 1,
              }
            }
          }]
      ]
}

Hey @mojodna. So the -fno-exceptions flag comes from node’s common.gypi file. The following is supposed to negate that, try adding:

...
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ]
...

The ! at the end is supposed to make sure that that flag is not used. Let me know if that works.

The real solution however would be to remove all instances of C+±style throw statements. That’s what I did for node-ffi, but I’m sure that won’t be possible for every module.