在Windows上使用共享库编译Node插件

时间:2019-02-05 15:06:37

标签: node.js windows node-gyp gyp node-addon

我需要在Windows上编译Node.js插件。我的问题是该插件依赖于共享库(libgeometry)。在Linux和MacOS上进行编译时,与libgeometry链接时没有问题,但是我真的不知道如何在Windows上做到这一点。我已经有libgeometry.dlllibgeometry.dll.a可用,但是如何在编译时链接它呢?

这是我的binding.gyp文件:

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

0 个答案:

没有答案