簡體   English   中英

使用 node-addon-api 的 node-gyp Node.js 插件不會覆蓋 linux 上的 c++ 版本

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

我已經成功地在 Mac OS 上為 node.js 構建了 c++ 插件。 嘗試移植到 Linux (Centos7)。

我正在使用 node.js 版本 12.10、node-gyp 版本 5.0.3、node-addon-api 版本 1.7.1。 Centos 版本 7.6.1810、gcc 版本 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)

我的綁定.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'
        ]
      }
    }
  ]
}

我嘗試在全局空間和條件下添加到 cflags_cc。 如果我兩者都做,它會將其添加到 g++ 命令行兩次。

這是 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 ...

我已經嘗試過-std=c++17-std=c++1z common.gypi文件具有以下相關值:

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

我看過很多帖子說要使用cflags_cc ,我是,但它只是添加它,而不是替換它,因此我依賴的 c++17 功能沒有編譯。

關於我做錯了什么的任何想法?

這解決了。 在 gcc 命令行上附加 c++ 標准確實有效 - 它遵循最后一個。 我遇到的問題是與被拉入的自定義 c++ 庫有關 - 不知何故, <iomanip> header 不包括在內,所以一旦我將其包含在我的 binding.cpp 文件中,編譯就可以工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM