我有一个由同事制作的节点扩展,我正在尝试通过node-gyp configure
(一切正常)然后node-gyp build
(fatal error, 'thread' file not found
)进行编译。现在,我相信这是gcc的一个问题,我在某处读到了我需要的标志-stdlib=libc+++
。我的binding.gyp
文件如下所示:
{
"targets": [
{
"target_name": "overcpu",
"sources": [ "overcpu.cpp" ],
"cflags" : [ "-stdlib=libc++" ]
}
]
}
但我仍然得到错误。我安装了XCode和开发人员工具,而且不满意我通过gcc
安装了brew
。不幸的是我一直收到同样的错误。
通过执行gcc -v
,我得到以下输出:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
我的gcc
是否有问题,或者node-gyp
(v1.0.1)是否让我发疯?
非常感谢!
答案 0 :(得分:9)
您还需要将-std=c++11
添加到cflags
参数列表中,以便完全激活C ++ 11支持。
更新:对于OSX(cflags
应该适用于BSD和Linux),您还需要在targets
设置中添加条件,如下所示:< / p>
{
"targets": [
{
"target_name": "overcpu",
"sources": [ "overcpu.cpp" ],
"cflags" : [ "-std=c++1", "-stdlib=libc++" ],
"conditions": [
[ 'OS!="win"', {
"cflags+": [ "-std=c++11" ],
"cflags_c+": [ "-std=c++11" ],
"cflags_cc+": [ "-std=c++11" ],
}],
[ 'OS=="mac"', {
"xcode_settings": {
"OTHER_CPLUSPLUSFLAGS" : [ "-std=c++11", "-stdlib=libc++" ],
"OTHER_LDFLAGS": [ "-stdlib=libc++" ],
"MACOSX_DEPLOYMENT_TARGET": "10.7"
},
}],
],
}
]
}