Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Node addon with shared library on Windows #1660

Closed
jonathan-roy opened this issue Feb 5, 2019 · 2 comments
Closed

Compile Node addon with shared library on Windows #1660

jonathan-roy opened this issue Feb 5, 2019 · 2 comments

Comments

@jonathan-roy
Copy link

  • 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
                }
            }
        }
    ]
}
@petercoin
Copy link

If you have a .lib file, you can try this

'libraries': [ 
    '<(module_root_dir)/native/lib/darwin/libgeometry.lib'
],

If you have only dll file, you have to search this function: LoadLibrary().
Like this:Explicit Loading of DLL

@rvagg
Copy link
Member

rvagg commented Jun 20, 2019

assuming this might be resolved by the above comment, closing due to staleness

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants