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

Set ENV

  1. export HOST=arm-linux-gnueabihf
  2. export CPP="${HOST}-gcc -E"
  3. export STRIP="${HOST}-strip"
  4. export OBJCOPY="${HOST}-objcopy"
  5. export AR="${HOST}-ar"
  6. export RANLIB="${HOST}-ranlib"
  7. export LD="${HOST}-ld"
  8. export OBJDUMP="${HOST}-objdump"
  9. export CC="${HOST}-gcc"
  10. export CXX="${HOST}-g++"
  11. export NM="${HOST}-nm"
  12. export AS="${HOST}-as"
  13. export LD="$CXX"
  14. export LINK="$CXX"
  15. export GYP_DEFINES="armv7=0"

Build

  1. node-gyp --arch arm configure build

Test

  1. root@imx6ul7d:~# node hello.js      
  2. world

TIP 0

  1. {
  2.   "targets": [
  3.     {
  4.       "target_name": "addon",
  5.       "sources": [ "test_api.cc" ],
  6. 	  "include_dirs" : ["sdk/inc"],
  7. 	  "link_settings": {"libraries": [ "-L/mnt/hgfs/tmp0511/sdk/lib"] },
  8. 	  "libraries": [ "-lpos", "-lpthread", "-lrt", "-lpng", "-liconv", "-lfreetype", "-lz" ],
  9.     }
  10.   ]
  11. }

TIP 1

  1. using v8::FunctionCallbackInfo;
  2. using v8::Isolate;
  3. using v8::Local;
  4. using v8::Object;
  5. using v8::String;
  6. using v8::Value;
  7. using v8::Number;
  8. using v8::Exception;
  9.  
  10. void js_Exchange(const FunctionCallbackInfo<Value>& args) {
  11.   Isolate* isolate = args.GetIsolate();
  12.  
  13.   int slot = args[0]->NumberValue();
  14.  
  15.   String::Utf8Value param1(args[1]->ToString());  
  16.   char *szApdu = *param1;  
  17.  
  18.   uint8_t apdu[300] = "\0";
  19.   MyAHex((uint8_t *)szApdu, apdu, strlen(szApdu));
  20.  
  21.   uint8_t rpdu[300] = "\0";
  22.   uint32_t rpdu_len = 0;
  23.   char szResult[300] = "\0";
  24.  
  25.   int ret = Exchange(slot, apdu, strlen(szApdu) / 2, rpdu, &rpdu_len);
  26.   if(0 == ret) {
  27.     MyHexA(rpdu, (uint8_t *)szResult, rpdu_len);
  28.     args.GetReturnValue().Set(String::NewFromUtf8(isolate, szResult));
  29.   } else {
  30.     args.GetReturnValue().Set(String::NewFromUtf8(isolate, ""));
  31.   }
  32. }

OpenCV3 On ARM

Source Code Dir

CMake-GUI Configure

Configure/Generate

Unix Makefiles
Specify options for cross-compiling

Choose ARM – LINUX

Operating System : arm-linux
C Compilers :
C++ Compilers :
Target Root : The Cross Compiler BIN Directory

CMAKE_INSTALL_PREFIX

make & make install

  1. make
  2. make install

Maybe Need It !


<>

The END

  1. tar jcvf opencv-arm.tar.bz2 opencv-arm/