Building Node addon on AIX

150 views
Skip to first unread message

Michael Pyne

unread,
Oct 14, 2014, 7:15:45 AM10/14/14
to nod...@googlegroups.com
I'm looking for help with building an addon for Node.js on AIX.

I'm working on an AIX 7.1 powerpc box, with Node.js 0.11.13 for powerpc from andrewlow/node on GitHub.
Make is GNU Make v 3.81; gcc is v4.8.2.

I don't have root access on the system, so I have installed Node to a folder in my homespace.

At the moment, I have a very simple "Hello, World" addon that I'm trying to use on AIX. The same cpp file has been added to a Visual Studio (2010) project on Windows 7, which has built successfully and can be required in Node.

I am able to build the addon using node-gyp on AIX; I copy the resulting .node file to the same folder as my node executable; when I try to require the add on, it fails with:

"Error: Module did not self-register.
    at Error (native)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)
    at repl:1:9
    at REPLServer.defaultEval (repl.js:130:27)
    at bound (domain.js:257:14)
    at REPLServer.runBound [as eval] (domain.js:270:12)
    at REPLServer.<anonymous> (repl.js:277:12)
"

The addon is defined in a single file:

#include <v8.h>
#include <node.h>
#include <node_object_wrap.h>
#include <string.h>

using namespace node;
using namespace v8;

class HelloWorld : public ObjectWrap
{
public:
    static Persistent<Function> constructor;

    static void init(Handle<Object> exports)
    {
        Isolate* isolate = Isolate::GetCurrent();
        Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
        tpl->SetClassName(String::NewFromUtf8(isolate, "HelloWorld"));
        tpl->InstanceTemplate()->SetInternalFieldCount(1);

        NODE_SET_PROTOTYPE_METHOD(tpl, "hello", Method);

        constructor.Reset(isolate, tpl->GetFunction());
        exports->Set(String::NewFromUtf8(isolate, "HelloWorld"), tpl->GetFunction());
    }

    static void Method(const FunctionCallbackInfo<Value>& args)
    {
        Isolate* isolate = Isolate::GetCurrent();
        HandleScope scope(isolate);
        args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
    }

    static void New(const FunctionCallbackInfo<Value>& args)
    {
        Isolate* isolate = Isolate::GetCurrent();
        HandleScope scope(isolate);
        HelloWorld* hw = new HelloWorld();
        hw->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
    }
};

Persistent<Function> HelloWorld::constructor;

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

    NODE_MODULE(hello, init);
}


I would be very grateful for any guidance on this.

Ben Noordhuis

unread,
Oct 14, 2014, 10:04:20 AM10/14/14
to nod...@googlegroups.com
Starting with v0.11.11, add-ons are supposed to self-register using a
constructor function. That's what the NODE_MODULE() macro does, it
generates a function with __attribute__((constructor)), and I believe
those are notoriously unreliable on AIX, see e.g. [0]. I don't have a
solution for you but at least now you know where to start digging.

[0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54791

Richard Lau

unread,
Nov 3, 2014, 1:58:43 PM11/3/14
to nod...@googlegroups.com
I'm able to successfully build and run your code sample on an AIX 6.1 box with GNU Make 3.82, gcc 4.6.1 and Node v0.11.13 built from v0.11.13-release-ppc from andrewlow/node on GitHub.

I created a simple binding.gyp file:
-bash-4.2$ cat binding.gyp
{
  'targets': [
      {
      'target_name': 'helloworld',
      'sources': [ 'helloworld.cc' ]
      }
   ]
}
-bash-4.2$

Following has been set:
-bash-4.2$ export CC=/opt/freeware/bin/gcc
-bash-4.2$ export CXX=/opt/freeware/bin/g++

I've had to export LDR_CNTRL=MAXDATA otherwise I was getting "process out of memory" from node-gyp when it attempts to grab and expand http://nodejs.org/dist/v0.11.13/node-v0.11.13.tar.gz.

-bash-4.2$ export LDR_CNTRL=MAXDATA=0x10000000@DSA
-bash-4.2$  ˜/sandbox/scratch/node-v0.11.13-aix-ppc64/bin/node ˜/sandbox/scratch/node-v0.11.13-aix-ppc64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure build
gyp info it worked if it ends with ok
gyp info using node...@0.13.0
gyp info using no...@0.11.13 | aix | ppc64
gyp http GET http://nodejs.org/dist/v0.11.13/node-v0.11.13.tar.gz
gyp http 200 http://nodejs.org/dist/v0.11.13/node-v0.11.13.tar.gz
gyp http GET http://nodejs.org/dist/v0.11.13/SHASUMS.txt
gyp http GET http://nodejs.org/dist/v0.11.13/SHASUMS.txt
gyp http 200 http://nodejs.org/dist/v0.11.13/SHASUMS.txt
gyp info node-gyp configure common.gypi copying "common.gypi" from /home/users/riclau/sandbox/scratch/node-v0.11.13-aix-ppc64/include/node/common.gypi to /home/users/riclau/.node-gyp/0.11.13/common.gypi
gyp http 200 http://nodejs.org/dist/v0.11.13/SHASUMS.txt
gyp info node-gyp configure node.exp copying "node.exp" from /home/users/riclau/sandbox/scratch/node-v0.11.13-aix-ppc64/include/node/node.exp to /home/users/riclau/.node-gyp/0.11.13/node.exp
gyp info spawn python
gyp info spawn args [ '/home/users/riclau/sandbox/scratch/node-v0.11.13-aix-ppc64/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/users/riclau/sandbox/scratch/aixaddon/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/users/riclau/sandbox/scratch/node-v0.11.13-aix-ppc64/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/users/riclau/.node-gyp/0.11.13/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/users/riclau/.node-gyp/0.11.13',
gyp info spawn args   '-Dmodule_root_dir=/home/users/riclau/sandbox/scratch/aixaddon',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn gmake
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
gmake: Entering directory `/home/users/riclau/sandbox/scratch/aixaddon/build'
gmake: Nothing to be done for `all'.
gmake: Leaving directory `/home/users/riclau/sandbox/scratch/aixaddon/build'
gyp info ok
-bash-4.2$  ˜/sandbox/scratch/node-v0.11.13-aix-ppc64/bin/node
> addon=require('./build/Release/helloworld.node')
{ HelloWorld: [Function: HelloWorld] }
> obj=new addon.HelloWorld()
{}
> obj.hello()
'world'
>

I'll see if I can get a later version of gcc.
Reply all
Reply to author
Forward
0 new messages