Skip to content

Compile Node addon with shared library on Windows #1660

@jonathan-roy

Description

@jonathan-roy
  • Node Version: v10.15.1
  • Platform: Windows 10 64 bits
  • Compiler: 15.9.21.664

I need to compile a Node.js addon on Windows. The problem I have is that this addon relies on a shared library (libgeometry). I had no problem linking against libgeometry at compile time on Linux and MacOS, but I really don't know how to do this on Windows. I already have libgeometry.dll and libgeometry.dll.a available, but how do I link against it at compile time?

Here is my binding.gyp file, working on Linux and MacOS:

{
    "targets": [
        {
            "target_name": "test",
            "sources": [
                "src/test.cpp"
            ],
            "include_dirs": [
                "<!@(node -p \"require('node-addon-api').include\")",
                "<(module_root_dir)/native/include"
            ],
            "conditions": [
                ["OS in \"linux\"", {
                    "libraries": [
                        "-lgeometry",
                        "-L<(module_root_dir)/native/lib/linux/libgeometry",
                        "-Wl,-rpath,$$ORIGIN/../../native/lib/linux/libgeometry"
                    ],
                    "defines": [
                        "NAPI_CPP_EXCEPTIONS"
                    ]
                }],
                ["OS in \"mac\"", {
                    "libraries": [
                        "-lgeometry",
                        "-L<(module_root_dir)/native/lib/darwin/libgeometry",
                        "-Wl,-rpath,@loader_path/../../native/lib/darwin/libgeometry"
                    ],
                    "xcode_settings": {
                        "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
                        "CLANG_CXX_LIBRARY": "libc++"
                    }
                }]
            ],
            "dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
            "cflags": ["-fexceptions"],
            "cflags_cc": ["-fexceptions"],
            "msvs_settings": {
                "VCCLCompilerTool": {
                    "ExceptionHandling": 1
                }
            }
        }
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions