node-waf cross compilation, creating a *.node file which is created under ubuntu and run in ARM processoe

416 views
Skip to first unread message

Pavi

unread,
Aug 28, 2012, 6:34:57 PM8/28/12
to nod...@googlegroups.com
Hi,

I have successfully cross compiled the node binary for version0.8. and running the same in the hardware.
Now i wrote *.cc and wscript file which helps in interfacing the C++ with the Java.
When i compile and build the same as "node-waf configure build" the compilation steps are successful, and i get a *.node file inside ./build/Release folder.
I copied the same from the ubuntu to the Target, but i get the below error.

root@bosch-nemid:~/Release-2# node ARM.js
[ 2971.577489] Alignment trap: not handling instruction e1923f9f at [<ffff0fc4>]
[ 2971.586303] Unhandled fault: alignment exception (0x011) at 0x0001bad5
Illegal instruction

Please find below the code of wscript:
srcdir = '.'
blddir = 'build'
VERSION = '0.1'

def set_options(opt):
  opt.tool_options("compiler_cxx")

def configure(conf):
  conf.check_tool("compiler_cxx")
  conf.check_tool("node_addon")

def build(bld):
  arch = ""
  if bld.env['DEST_CPU'] == 'x86_64':
    arch = "arch=x64"
    print "x86"
  elif bld.env['DEST_CPU'] == 'x86':
    arch = "arch=x86"
    print "x86"
  elif bld.env['DEST_CPU'] == 'arm':
    arch = "arch=arm"
    print "arm_1"
  elif bld.env['DEST_CPU'] == 'mips':
    arch = "arch=mips"
    print "arm_2"
  else:
    raise Exception(bld.env['DEST_CPU'], "is not one of these supported architectures: x86, x86_64, arm, mips")
  print "Working fine with arm"
  arch = "arch=arm"
  cross_arch = True
  bld.env['AR'] = '/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/bin/arm-montavista-linux-gnueabi-ar'
  bld.env['CC'] = '/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/bin/arm-montavista-linux-gnueabi-gcc'
  bld.env['LINK_CC'] = '/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/bin/arm-montavista-linux-gnueabi-gcc'
  bld.env['LIBDIR'] = '/home/pavincoll/Desktop/ARMRFS3/usr/lib'
  obj = bld.new_task_gen("cxx", "shlib", "node_addon")
  obj.target = "aqARM"
  obj.source = "NJSAQ.cc"
  obj.includes = ["/home/pavincoll/Desktop/ARMRFS3/usr/include", "/home/pavincoll/Desktop/ARMRFS3/usr/include/alsa", "/home/pavincoll/Desktop/ARMRFS3/usr/include/curl", "/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/arm-montavista-linux-gnueabi/target-toolchain/arm-montavista-linux-gnueabi/libc/usr/bin" , "/home/pavincoll/Desktop/ARMRFS3/usr/lib", "/home/pavincoll/workspace/aqstub/src" ]
  obj.lib = ["pthread","aqARM", "sqARM_1", "spARM"]


Note:

I have a folder in my Ubuntu which replicated my Target Root file system,
And i have made sure i point to that as the Library Directory path.
Also i am not using the Default Gcc compiler instead i am using the MontaVista C++ compiler.
I set system env like CC,CPP,AR,RANLIB Variables to point to the rite Montavista binary path.

can some one help.
thanks in advance.

Pavi


mscdex

unread,
Aug 28, 2012, 6:40:15 PM8/28/12
to nodejs
On Aug 28, 6:34 pm, Pavi <pavinc...@gmail.com> wrote:
> Please find below the code of wscript:

First thing you should do is switch to gyp.

Pavi

unread,
Aug 29, 2012, 7:08:17 PM8/29/12
to nod...@googlegroups.com
I finaaly managed to  get the below error, when created the *.node using gyp in the Ubuntu platform and copied in to the Target.

root@bosch-nemid:~/Release-2/build/Release/lib.target# node ARM.js

module.js:480
  process.dlopen(filename, module.exports);
          ^
Error: /home/root/Release-2/build/Release/lib.target/hu.node: undefined symbol: init
    at Object.Module._extensions..node (module.js:480:11)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/home/root/Release-2/build/Release/lib.target/ARM.js:1:78)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)


Please find below my binding.gyp code,
{
  'targets' : [
    {
      'target_name': 'hu',
      'type': 'shared_library',
      'sourcess': [ 'NJSAQ.cc' ],
      'include_dirs': ['/home/pavincoll/Desktop/ARMRFS3/usr/include', '/home/pavincoll/Desktop/ARMRFS3/usr/include/alsa', '/home/pavincoll/Desktop/ARMRFS3/usr/include/curl', '/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/arm-montavista-linux-gnueabi/target-toolchain/arm-montavista-linux-gnueabi/libc/usr/bin' , '/home/pavincoll/Desktop/ARMRFS3/usr/lib', '/home/pavincoll/workspace/aqstub/src'],
      'link_settings': {
        'libraries': ['/usr/local/lib/libaqARM.so', '/usr/local/lib/libsqARM_1.so', '/usr/local/lib/libspARM.so']
       }
    }
  ]
}


On Wednesday, August 29, 2012 12:03:48 PM UTC-7, Pavi wrote:
Some times for the same i get the below error, when created the *.node using gyp in the Ubuntu platform and copied in to the Target.

root@bosch-nemid:~/Release-2/build/Release/lib.target# node ARM.js

module.js:480
  process.dlopen(filename, module.exports);
          ^
Error: /home/root/Release-2/build/Release/lib.target/hu.node: undefined symbol: init
    at Object.Module._extensions..node (module.js:480:11)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/home/root/Release-2/build/Release/lib.target/ARM.js:1:78)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)


Please find below my binding.gyp code,
{
  'targets' : [
    {
      'target_name': 'hu',
      'type': 'shared_library',
      'sourcess': [ 'NJSAQ.cc' ],
      'include_dirs': ['/home/pavincoll/Desktop/ARMRFS3/usr/include', '/home/pavincoll/Desktop/ARMRFS3/usr/include/alsa', '/home/pavincoll/Desktop/ARMRFS3/usr/include/curl', '/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/arm-montavista-linux-gnueabi/target-toolchain/arm-montavista-linux-gnueabi/libc/usr/bin' , '/home/pavincoll/Desktop/ARMRFS3/usr/lib', '/home/pavincoll/workspace/aqstub/src'],
      'link_settings': {
        'libraries': ['/usr/local/lib/libaqARM.so', '/usr/local/lib/libsqARM_1.so', '/usr/local/lib/libspARM.so']
       }
    }
  ]
}


Please find below the *.cc code,
 #include <v8.h>
#include <node.h>

#include "aq_api.h"

using namespace node;
using namespace v8;

/**
 * Checks that the passed V8 Object is of type Function and casts it
 * to a Function with the specified name.
 *
 * @param I Object to be cast to a Function.
 * @param VAR Name of the local Function variable to be created and set
 * to I.
 */
#define REQ_FUN_ARG(I, VAR)                                           \
if (args.Length() <= (I) || !args[I]->IsFunction())               \
return ThrowException(Exception::TypeError(                   \
String::New("Argument " #I " must be a function")));  \
Local<Function> VAR = Local<Function>::Cast(args[I]);

/**
 * Node.js V8 addon wrapper class for the Audio Manager.
 */
class NJSAQ : ObjectWrap
{
private:
static const int SET_PHONE_CALL_PERMISSION =2;
aq _aq;

public:

static Persistent<FunctionTemplate> s_ct;

/**
* V8 module initializer.
*/
static void Init(Handle<Object> target)
{
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(New);

s_ct = Persistent<FunctionTemplate>::New(t);
s_ct->InstanceTemplate()->SetInternalFieldCount(1);
s_ct->SetClassName(String::NewSymbol("NJSAQ"));

NODE_SET_PROTOTYPE_METHOD(s_ct, "aqSetPhoneCallPermission", aqSetPhoneCallPermissionAsync);

target->Set(String::NewSymbol("NJSAQ"),
s_ct->GetFunction());
}

/**
* Default constructor.
*/
NJSAQ()
{
}

/**
* Default destructor.
*/
~NJSAQ()
{
}

/**
* V8 module constructor.
*/
static Handle<Value> New(const Arguments& args)
{
HandleScope scope;
NJSAQ* am = new NJSAQ();
am->Wrap(args.This());
return args.This();
}

/**
* Data passed between dictationAsync() asynchronous functions.
*/

struct AQ_SET_PHONECALL_PERMISSIONBaton_t
{

NJSAQ *am;
Persistent<Function> callback;
bool bCallpermission;
};

static Handle<Value> aqSetPhoneCallPermissionAsync(const Arguments& args)
{

HandleScope scope;

REQ_FUN_ARG(SET_PHONE_CALL_PERMISSION - 1, callback);

NJSAQ* am = ObjectWrap::Unwrap<NJSAQ>(args.This());

AQ_SET_PHONECALL_PERMISSIONBaton_t * baton = new AQ_SET_PHONECALL_PERMISSIONBaton_t();

baton->callback = Persistent<Function>::New(callback);
baton->am = am;

baton->bCallpermission = args[0]->BooleanValue();

am->Ref();

eio_custom(eioaqSetPhoneCallPermissionAsync, EIO_PRI_DEFAULT, eioaqSetPhoneCallPermissionAsyncPost, baton);
ev_ref(EV_DEFAULT_UC);

return Undefined();
}

/**
*
*/
static void eioaqSetPhoneCallPermissionAsync(eio_req *req)
{

AQ_SET_PHONECALL_PERMISSIONBaton_t *baton = static_cast<AQ_SET_PHONECALL_PERMISSIONBaton_t*>(req->data);

baton->am->_aq.aqSetPhoneCallPermission(baton->bCallpermission);

}

/**
*
*/
static int eioaqSetPhoneCallPermissionAsyncPost(eio_req *req)
{

HandleScope scope;
AQ_SET_PHONECALL_PERMISSIONBaton_t *baton = static_cast<AQ_SET_PHONECALL_PERMISSIONBaton_t *>(req->data);
ev_unref(EV_DEFAULT_UC);
baton->am->Unref();

Local<Value> argv[0];


TryCatch try_catch;

baton->callback->Call(Context::GetCurrent()->Global(), 0, argv);

if (try_catch.HasCaught()) {
FatalException(try_catch);
}

baton->callback.Dispose();

delete baton;


return 0;
}
};

Persistent<FunctionTemplate> NJSAQ::s_ct;

extern "C" {
  static void init (Handle<Object> target)
  {
 NJSAQ::Init(target);
  }

  NODE_MODULE(aqARM, init);

Ben Noordhuis

unread,
Aug 29, 2012, 7:18:16 PM8/29/12
to nod...@googlegroups.com
On Thu, Aug 30, 2012 at 1:08 AM, Pavi <manic...@gmail.com> wrote:
> extern "C" {
> static void init (Handle<Object> target)

init must be non-static or it won't be visible to dlsym(). But
preferably use the NODE_MODULE macro.

Pavi

unread,
Aug 29, 2012, 7:59:40 PM8/29/12
to nod...@googlegroups.com
Hi Ben,

I removed the static from all the places from the above code, and i still get the same error.
Also do you mean NODE_SET_METHOD, since i am using NODE_MODULE to call init function.

Pavi

Skyler Brungardt

unread,
Aug 29, 2012, 9:23:14 PM8/29/12
to nod...@googlegroups.com
4

--
Skyler Brungardt

On Wednesday, August 29, 2012 at 11:51, Pavi wrote:

Hi,

I shifted to gyp, and wrote binding.gyp, but still when i copy over the *.node file to Hardware which is successfully created in my ubuntu cause me the following error,

[11893.676924] Alignment trap: not handling instruction e1923f9f at [<ffff0fc4>]
[11893.686520] Unhandled fault: alignment exception (0x011) at 0x0001ba4d
Illegal instruction

Please find below my Binding.gyp code,
{
  'targets' : [
    {
      'target_name': 'hu',
      'type': 'shared_library',
      'sourcess': [ 'NJSAQ.cc' ],
      'include_dirs': ['/home/pavincoll/Desktop/ARMRFS3/usr/include', '/home/pavincoll/Desktop/ARMRFS3/usr/include/alsa', '/home/pavincoll/Desktop/ARMRFS3/usr/include/curl', '/opt/tooling/mvista/MV_20110822/symphony-ivi-2.6.34/tools/tools/arm-gnueabi/arm-montavista-linux-gnueabi/target-toolchain/arm-montavista-linux-gnueabi/libc/usr/bin' , '/home/pavincoll/Desktop/ARMRFS3/usr/lib', '/home/pavincoll/workspace/aqstub/src'],
      'link_settings': {
        'libraries': ['/usr/local/lib/libaqARM.so', '/usr/local/lib/libsqARM_1.so', '/usr/local/lib/libspARM.so']
       }
    }
  ]
}

Pavi


On Tuesday, August 28, 2012 3:40:24 PM UTC-7, mscdex wrote:

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Ben Noordhuis

unread,
Aug 30, 2012, 7:54:10 AM8/30/12
to nod...@googlegroups.com
On Thu, Aug 30, 2012 at 1:59 AM, Pavi <manic...@gmail.com> wrote:
> Hi Ben,
>
> I removed the static from all the places from the above code, and i still
> get the same error.
> Also do you mean NODE_SET_METHOD, since i am using NODE_MODULE to call init
> function.

Sorry, for some reason my mail reader didn't show the last two lines
of your email. What does `nm yourmodule.node | grep -E 'init|_module'`
print?

Pavi

unread,
Aug 30, 2012, 1:31:38 PM8/30/12
to nod...@googlegroups.com
 I removed the static from all the places from the above code, and i still  get the same error.Also do you mean NODE_SET_METHOD, since i am using NODE_MODULE to call init function.  

Pavi

unread,
Aug 30, 2012, 1:33:19 PM8/30/12
to nod...@googlegroups.com
Hi Skyler,

For some reason i am not able to view your mess , it just shows "4 --".
Can you please reply back.

Skyler Brungardt

unread,
Aug 30, 2012, 1:37:57 PM8/30/12
to nod...@googlegroups.com
Hi Pavi,

That's a mail-reader fail.  That was meant for another thread.  Kindly disregard!  :-)

-- 
Skyler Brungardt

Reply all
Reply to author
Forward
0 new messages