C ++ / NodeJS包括其他文件N-API

时间:2019-07-04 17:09:53

标签: c++ include node-addon-api

我想在我的N-API项目中包括另一个源/头文件。当我这样做时,它可以正常编译和链接,但是在执行时,它抱怨找不到另一个文件中的功能。

test.h

TODO

test.c

function runReplaceInSheet(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Underlevel");
  //  get the current data range values as an array
  //  Fewer calls to access the sheet -> lower overhead 
  var values = sheet.getDataRange().getValues();  

var range = sheet.getDataRange();
var replaceObj = {
  //to_replace: imgur id
  T: 'Dxl893F',
  A: 'omc7F9l',
  R: '12ZmSp3',
  M: 'kh7RqBD',
  H: 'u0O7fsS',
  F: 'Hbs3TuP',
};
var regex = new RegExp('^(' + Object.keys(replaceObj).join('|') + ')$', 'g');// /^(T|A|R|M|H|F)$/
function replacer(match) {
  return '=image("https://i.imgur.com/' + replaceObj[match] + '.png")';
}
var data = range.getValues();
range.setFormulas(
  range.getFormulas().map(function(e, i) {//i=index of row(e)
    return e.map(function(f, j) {//j = index of column(f)
      return f === "" ? data[i][j].toString().replace(regex, replacer) : f;
    });
  })
);
}

main.h

int addExt(int a, int b);

main.cpp

#include "test.h"

int addExt(int a, int b)
{
    return a+b;
}

binding.gyp

#include <napi.h>
#include "test.h"

Napi::Number Add(const Napi::CallbackInfo& info);
Napi::Object Init(Napi::Env env, Napi::Object exports);

在标准C ++中运行此命令时,一切运行正常。在构建土壤部门中,我看到main.o和test.o的生成正确。但是,在运行时,出现错误: #include "main.h" Napi::Number Add(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); if (info.Length() < 2 || !info[0].IsNumber() || !info[1].IsNumber()) { Napi::TypeError::New(env, "Number expected").ThrowAsJavaScriptException(); } Napi::Number first = info[0].As<Napi::Number>(); Napi::Number second = info[1].As<Napi::Number>(); int returnValue = addExt(first.Int32Value(), second.Int32Value()); return Napi::Number::New(env, returnValue); } Napi::Object Init(Napi::Env env, Napi::Object exports) { exports.Set("add", Napi::Function::New(env, Add)); return exports; } NODE_API_MODULE(jsInvMpu6050, Init)

0 个答案:

没有答案