所以我一直在研究 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/