Skip to content

Instantly share code, notes, and snippets.

@polaris
Created January 14, 2012 20:02
Show Gist options
  • Save polaris/1612694 to your computer and use it in GitHub Desktop.
Save polaris/1612694 to your computer and use it in GitHub Desktop.
Problems loading node files with node v0.7.0-pre
$ node-waf clean configure build
'clean' finished successfully (0.014s)
Setting srcdir to : /Users/jan/Projects/node.js/nodekeeper2
Setting blddir to : /Users/jan/Projects/node.js/nodekeeper2/build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : ok /Users/jan/.node_libraries
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.048s)
Waf: Entering directory `/Users/jan/Projects/node.js/nodekeeper2/build'
[1/2] cxx: nodekeeper.cc -> build/Release/nodekeeper_1.o
[2/2] cxx_link: build/Release/nodekeeper_1.o -> build/Release/nodekeeper.node
Waf: Leaving directory `/Users/jan/Projects/node.js/nodekeeper2/build'
'build' finished successfully (0.274s)
$ node test.js
node.js:216
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Unable to load shared library /Users/jan/Projects/node.js/nodekeeper2/build/Release/nodekeeper.node
at Object..node (module.js:465:11)
at Module.load (module.js:353:31)
at Function._load (module.js:310:12)
at Module.require (module.js:359:17)
at require (module.js:370:17)
at Object.<anonymous> (/Users/jan/Projects/node.js/nodekeeper2/test.js:3:18)
at Module._compile (module.js:434:26)
at Object..js (module.js:452:10)
at Module.load (module.js:353:31)
at Function._load (module.js:310:12)
#include "nodekeeper.h"
using namespace v8;
Persistent<FunctionTemplate> NodeKeeper::constructor;
void NodeKeeper::Init(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
Local<String> name = String::NewSymbol("NodeKeeper");
constructor = Persistent<FunctionTemplate>::New(tpl);
// ObjectWrap uses the first internal field to store the wrapped pointer.
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(name);
// Add all prototype methods, getters and setters here.
NODE_SET_PROTOTYPE_METHOD(constructor, "value", Value);
// This has to be last, otherwise the properties won't show up on the
// object in JavaScript.
target->Set(name, constructor->GetFunction());
}
NodeKeeper::NodeKeeper(int val)
: ObjectWrap(),
value_(val) {}
Handle<Value> NodeKeeper::New(const Arguments& args) {
HandleScope scope;
if (!args.IsConstructCall()) {
return ThrowException(Exception::TypeError(
String::New("Use the new operator to create instances of this object."))
);
}
if (args.Length() < 1) {
return ThrowException(Exception::TypeError(
String::New("First argument must be a number")));
}
// Creates a new instance object of this type and wraps it.
NodeKeeper* obj = new NodeKeeper(args[0]->ToInteger()->Value());
obj->Wrap(args.This());
return args.This();
}
Handle<Value> NodeKeeper::Value(const Arguments& args) {
HandleScope scope;
// Retrieves the pointer to the wrapped object instance.
NodeKeeper* obj = ObjectWrap::Unwrap<NodeKeeper>(args.This());
return scope.Close(Integer::New(obj->value_));
}
void RegisterModule(Handle<Object> target) {
NodeKeeper::Init(target);
}
NODE_MODULE(nodekeeper, RegisterModule);
#ifndef NODEKEEPER_H
#define NODEKEEPER_H
#include <node.h>
class NodeKeeper : public node::ObjectWrap {
public:
static v8::Persistent<v8::FunctionTemplate> constructor;
static void Init(v8::Handle<v8::Object> target);
protected:
NodeKeeper(int value);
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> Value(const v8::Arguments& args);
private:
int value_;
};
#endif // NODEKEEPER_H
var nodekeeper = require('./build/Release/nodekeeper');
#!/usr/bin/env python
def set_options(ctx):
ctx.tool_options('compiler_cxx')
def configure(ctx):
ctx.env.append_value('LINKFLAGS', '-flat_namespace -undefined suppress'.split())
#ctx.env.append_value('LINKFLAGS', '-undefined dynamic_lookup'.split())
ctx.check_tool('compiler_cxx')
ctx.check_tool('node_addon')
def build(ctx):
t = ctx.new_task_gen('cxx', 'shlib', 'node_addon')
t.source = ['nodekeeper.cc']
t.target = 'nodekeeper'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment