NAPI addon throwing "undefined symbol: omp_get_max_threads" from .node file

893 Views Asked by At

This seems like a weird error. I tried debugging the native code line by line and this error seems to happen out of nowhere, like at the end of a function call. It's seem to be caused by certain parts of code in the native library I'm using, because if I remove some function calls, this error seems to disappear.

node version: 12.16.3 node-gyp version: 6.1.0

By the way, I'm using nvm. If that helps.

After googling around omp_get_max_threads, I've tried adding -fopenmp to compiler flags in binding.gyp file like so.

{
    "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\")"
        ]
    }]
}

Still, the problem persists. By the way, I'm using node-addon-api package, not n-api directly.

1

There are 1 best solutions below

0
On

Urghh..

Just after posting this, I found out that you have to explicitly add libgomp to 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\")"
        ]
    }]
}