如何通过node-gyp提供静态C库函数?

时间:2019-02-27 13:21:04

标签: c++ node.js node-gyp node-addon-api

我尝试通过node-gyp和node-addon-api编译node_module。编译没有错误,但是我无法公开静态库中的函数。 (与最终节点文件相同,小于静态库abc.a)

binding.gyp

{
    "targets": [
        {
            "target_name": "test",
            "cflags!": [ "-fno-exceptions" ],
            "cflags_cc!": [ "-fno-exceptions" ],
            "sources": [
                "/data/abc.h",
                "main.cpp"
            ],
            'include_dirs': [
                "<!@(node -p \"require('node-addon-api').include\")"
            ],
            'libraries': [
                "/data/abc.a"
            ],
            'dependencies': [
                "<!(node -p \"require('node-addon-api').gyp\")"
            ],
            'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
        }
    ]
}

main.cpp

/* main.cpp */
#include <napi.h>
#include "abc.h"

Napi::Object InitAll(Napi::Env env, Napi::Object exports) {

  return exports;
}

NODE_API_MODULE(testaddon, InitAll)

main.js (用于公开对象)

const testAddon = require('./build/Release/apostlib');

console.log(testAddon);

module.exports = testAddon;

0 个答案:

没有答案