c++ - 强制 node-gyp 使用 C++11

标签 c++ node.js c++11 node-gyp

所以我一直在研究 NodeJS 的 C/C++ Addons 功能,但是由于我对这个概念还比较陌生,所以我遇到了一个大问题。本质上,我编写的 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" ]
    }
  ]
}

谢谢

最佳答案

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

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

关于c++ - 强制 node-gyp 使用 C++11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42586573/

相关文章:

c++ - 如何在 XML 文本(标签内)中搜索换行符?

javascript - 抓取 html 页面并将其转换为 json 对象

node.js - Node 二进制Buffer.toString(),转换回Buffer

c++ - 安装 POD

c++ - 为什么要使用已删除的右值引用构造函数?

c++ - 尝试将 std::make_unique 声明为我的模板类的友元时 MSVC 出错

c++ - C++ 标准是否保证 std::basic_string::npos + 1 == 0?

javascript - 找不到模块 '@mdx-js/mdx' - Gatsby

c++ - 如何在 C++ 中将正则表达式 "Grouping"用于多个正则表达式?

c++ - 将 OpenDDS 与 QTCreator 集成并运行