强制node-gyp使用C++11

Oli*_*han 3 c++ node.js c++11 node-gyp

所以我用 NodeJS 搞乱了 C/C++ 插件功能,但是由于我对这个概念相对较新,我遇到了一个大问题。本质上,我编写的 C++ 程序需要 RegEx 库,但是当我运行时,node-gyp rebuild我收到以下错误。

CXX(target) Release/obj.target/addon/main.o
../main.cpp:15:10: fatal error: 'regex' file not found
#include <regex>
         ^
1 error generated.
Run Code Online (Sandbox Code Playgroud)

当使用 Xcode(我使用 Mac)构建我的项目时,在我开始将其转换为 C/C++ 插件之前,该项目构建得非常好并且按预期运行。

我做了一些挖掘,我相信正则表达式库仅在 C++11 中可用,尽管我不太确定 node-gyp 是否使用它,所以我如何能够使用它而不是默认值进行构建,或以其他方式手动包含该库(如果可以的话)。

我的程序看起来像这样,

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <regex> <-- Throws Error Here

#include <node.h>

using namespace v8;

// Rest of the code (compiler doesn't reach past this point)
Run Code Online (Sandbox Code Playgroud)

我的 binding.gyp 文件如下所示,

{
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "main.cpp" ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Oli*_*han 5

好的,就像编辑文件一样简单,bindings.gyp使其看起来如下,这意味着它是使用 C++11 构建的。

{
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "main.cpp" ],
      'xcode_settings': {
        'OTHER_CFLAGS': [
          "-std=c++11",
          "-stdlib=libc++"
        ],
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)