Node-gyp无法编译nodejs扩展名('致命错误,未找到线程'文件)

时间:2014-09-03 13:01:30

标签: c++ node.js gcc node-gyp

我有一个由同事制作的节点扩展,我正在尝试通过node-gyp configure(一切正常)然后node-gyp buildfatal 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)是否让我发疯?

非常感谢!

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"
            },
          }],
        ],
    }
    ]
}