node-gpy 使用lib和dll

1. 创建静态库 "hello.lib"

  • release x64
  • 编译前,选择多线程MT,否则可能出现这个错误(error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MT_StaticRelease”)
  • 生成解决方案

2. gyp设置

  • 将hello.lib拷贝到 /<(project_dir)deps/hello/hello.lib
  • 将hello.h拷贝到/<(project_dir)deps/hello/include/hello.h
{
    'variables': {
    },
    "targets": [
        {
            "target_name": "node-windows-x64",
            "sources": [
                "src/main.cpp",
            ],
            "include_dirs": [
                "<!@(node -p \"require('node-addon-api').include\")",
                '<(module_root_dir)/deps/hello/include', # 头文件
                '<(module_root_dir)/deps/asmjit/include',
            ],
            'defines': ['NAPI_DISABLE_CPP_EXCEPTIONS'],
            'libraries': [
                '-l<(module_root_dir)/deps\\asmjit\\asmjit.lib',
                '-l<(module_root_dir)/deps\\asmjit\\asmjit.lib', # lib文件
            ],
            "copies": [
                {
                    "destination": "<(module_root_dir)/build/Release/",
                    "files": ["<(module_root_dir)/deps\\asmjit\\asmjit.dll"]
                }
            ]
        },
    ]
}

3. 运行

node-gyp configure --release && node-gyp build --release
posted @ 2021-04-15 09:37  Ajanuw  阅读(582)  评论(0编辑  收藏  举报