强制 node-gyp 使用 C++11

3

我最近在尝试使用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.

当我使用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)

我的binding.gyp文件如下所示,
{
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "main.cpp" ]
    }
  ]
}

谢谢

1个回答

5

好的,所以只需编辑bindings.gyp文件,使其看起来如下所示,这意味着它使用C++11构建。

{
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "main.cpp" ],
      'xcode_settings': {
        'OTHER_CFLAGS': [
          "-std=c++11",
          "-stdlib=libc++"
        ],
      }
    }
  ]
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接