Water's Home

Just another Life Style

0%

Cross compile with Node.js C++ Addons to ARM

Set ENV

export HOST=arm-linux-gnueabihf
export CPP=”${HOST}-gcc -E”
export STRIP=”${HOST}-strip”
export OBJCOPY=”${HOST}-objcopy”
export AR=”${HOST}-ar”
export RANLIB=”${HOST}-ranlib”
export LD=”${HOST}-ld”
export OBJDUMP=”${HOST}-objdump”
export CC=”${HOST}-gcc”
export CXX=”${HOST}-g++”
export NM=”${HOST}-nm”
export AS=”${HOST}-as”
export LD=”$CXX”
export LINK=”$CXX”
export GYP_DEFINES=”armv7=0”

Build

node-gyp –arch arm configure build

Test

root@imx6ul7d:~# node hello.js
world

TIP 0

{
“targets”: [
{
“target_name”: “addon”,
“sources”: [ “test_api.cc” ],
“include_dirs” : [“sdk/inc”],
“link_settings”: {“libraries”: [ “-L/mnt/hgfs/tmp0511/sdk/lib”] },
“libraries”: [ “-lpos”, “-lpthread”, “-lrt”, “-lpng”, “-liconv”, “-lfreetype”, “-lz” ],
}
]
}

TIP 1

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Number;
using v8::Exception;

void js_Exchange(const FunctionCallbackInfo& args) {
Isolate* isolate = args.GetIsolate();

int slot = args[0]->NumberValue();

String::Utf8Value param1(args[1]->ToString());
char *szApdu = *param1;

uint8_t apdu[300] = “\0”;
MyAHex((uint8_t *)szApdu, apdu, strlen(szApdu));

uint8_t rpdu[300] = “\0”;
uint32_t rpdu_len = 0;
char szResult[300] = “\0”;

int ret = Exchange(slot, apdu, strlen(szApdu) / 2, rpdu, &rpdu_len);
if(0 == ret) {
MyHexA(rpdu, (uint8_t *)szResult, rpdu_len);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, szResult));
} else {
args.GetReturnValue().Set(String::NewFromUtf8(isolate, “”));
}
}