简体   繁体   中英

node-gyp Node.js addon using node-addon-api is not overriding c++ version on linux

I have successfully built a c++ addon for node.js on Mac OS. Trying to port to Linux (Centos7).

I am using node.js version 12.10, node-gyp version 5.0.3, node-addon-api version 1.7.1. Centos version 7.6.1810, gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)

My binding.gyp:

{
  "targets": [
    {
      "target_name": "hsm",
      ### The sources list must be relative to the current directory.
      "sources": [ "../../../my_project/src/mypackage/binding-napi.cpp" ],
      "include_dirs": [
        # this is for using n-api vs nan
        "<!@(node -p \"require('node-addon-api').include\")"
      ],
      'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
      "cflags_cc": [
        "-fexceptions",
      ],
      "conditions": [
        ['OS=="linux"', {
           "cflags_cc": [
             "-std=c++17"
           ]
        }],
      ],
      'xcode_settings': {
        'MACOSX_DEPLOYMENT_TARGET':
          '10.14',
        'CLANG_CXX_LANGUAGE_STANDARD':
          'c++17',
        'GCC_ENABLE_CPP_EXCEPTIONS':
          'YES',
          # 'gnu++1z'
        'OTHER_CFLAGS': [
          "-fcxx-exceptions",
          '-Wno-unused-result'
        ]
      }
    }
  ]
}

I have tried adding to the cflags_cc, both in the global space and conditions. If I do both, it adds it to the g++ command line twice.

Here are the resulting flags on the g++

... fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 
-fno-omit-frame-pointer 
-fno-rtti 
-fno-exceptions 
-std=gnu++1y 
-fexceptions 
-std=c++17 ...

I have tried both -std=c++17 and -std=c++1z . the common.gypi file has the following related values:

...
      [ 'OS in "linux freebsd openbsd solaris android aix cloudabi"', {
        'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],
        'cflags_cc': [ '-fno-rtti', '-fno-exceptions', '-std=gnu++1y' ],
...

I have seen many posts that say to use the cflags_cc , and I am, but its only adding it, not replacing, and therefore the c++17 features that i depend on are not compiling.

Any ideas of what I am doing wrong?

This is solved. The appending of the c++ standard on the gcc command line DOES work - it obeys the last one. The problem I had was with the custom c++ library(ies) that was(were) being pulled in - somehow the <iomanip> header was not included, so once I included in my binding.cpp file, compilation worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM