【问题标题】:NAPI addon throwing "undefined symbol: omp_get_max_threads" from .node fileNAPI插件从.node文件中抛出“未定义的符号:omp_get_max_threads”
【发布时间】:2020-05-07 06:09:19
【问题描述】:

这似乎是一个奇怪的错误。 我尝试逐行调试本机代码,这个错误似乎突然发生,就像在函数调用结束时一样。 这似乎是由我正在使用的本机库中的某些代码部分引起的,因为如果我删除一些函数调用,这个错误似乎消失了。

节点版本:12.16.3 节点gyp版本:6.1.0

顺便说一句,我正在使用 nvm。如果有帮助的话。

在搜索了 omp_get_max_threads 之后,我尝试像这样将 -fopenmp 添加到 binding.gyp 文件中的编译器标志中。

{
    "targets": [{
        "target_name": "custom_addon",
        "cflags!": [ "-fno-exceptions" ],
        "cflags_cc!": [ "-fno-exceptions" ],
        "cflags": ["-fopenmp"],
        "cflags_cc": ["-fopenmp"],
        "sources": [
            "custom_addon.cpp"
        ],
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")",
            "${workspaceRoot}"
        ],
        'libraries': [],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ]
    }]
}

不过,问题仍然存在。 顺便说一句,我使用的是 node-addon-api 包,而不是直接使用 n-api。

【问题讨论】:

    标签: node.js node-gyp node-addon-api n-api


    【解决方案1】:

    呃……

    刚发完这篇文章,我发现你必须明确地将 libgomp 添加到 binding.gyp 中。

    {
        "targets": [{
            "target_name": "custom_addon",
            "cflags!": [ "-fno-exceptions" ],
            "cflags_cc!": [ "-fno-exceptions" ],
            "cflags": ["-fopenmp"],
            "cflags_cc": ["-fopenmp"],
            "sources": [
                "custom_addon.cpp"
            ],
            'include_dirs': [
                "<!@(node -p \"require('node-addon-api').include\")",
                "${workspaceRoot}"
            ],
            'libraries': ["/usr/lib/x86_64-linux-gnu/libgomp.so.1"],
            'dependencies': [
                "<!(node -p \"require('node-addon-api').gyp\")"
            ]
        }]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多