node-gyp icon indicating copy to clipboard operation
node-gyp copied to clipboard

Link with static library generated by GCC on Windows

Open tdewolff opened this issue 2 years ago • 0 comments

I'm using node-gyp to create prebuilt binaries for all platforms using the GitHub Actions CI. The library is a native addon using Go. The Go code (library.go) and the accompanying C interface (library.c) are first compiled using Go/CGO (which uses GCC) to a static C library (library.a). Go only support GCC and not MSVC so I don't have much choice, but at least it's not C++.

Next I try to build the node-gyp library by linking against the library.a, which is using the MSVC toolchain (again, not much choice here). It builds fine, but upon using the library I get: Error: Module did not self-register. It works find on Linux or MacOS (since they use GCC perhaps), so I figured this might be a problem of using MSVC and GCC on Windows, however it seems to build and link fine...? The binding.gyp looks like:

{
    "targets": [{
        "target_name": "library",
        "product_extension": "node",
        "type": "<(library)",
        "cflags": ["-Wall"],
        "ldflags": ["-s"],
        "sources": ["library.c"],
        "libraries": ["../library.a"],
    }],
}

How can I debug this error further? Thanks for the help!

tdewolff avatar May 23 '23 00:05 tdewolff