0

I want to use CImg library to deal images in node.js,so i write an node addon to do it. The compile is success, i run node-gyp build commond, that's ok.

But when i run the node program,the follow error occurs:

[root@localhost hcaptha]# node index.js 

module.js:485
  process.dlopen(filename, module.exports);
          ^
Error: /usr/local/nodejs/hcaptha/build/Release/hcaptha.node: undefined symbol: XSendEvent
    at Object.Module._extensions..node (module.js:485: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> (/usr/local/nodejs/hcaptha/lib/hcap.js:1:75)
    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)

the binding.gyp file is:

{
  "targets":[
    {
      "target_name": "hcaptha",
      "sources": [ "addon/hcaptha.cc" ,"addon/cap.cc"],
      'cflags': ['-fexceptions','-O2','-Dcimg_use_png'],//the configure using CImg lib
      'cflags_cc': ['-fexceptions','-O2','-Dcimg_use_png']
    }
  ]
}

cap.cc code:

#include <node.h>
#include <string>
#include <iostream>
#include "cap.h"
#include "CImg-1.5.3/CImg.h"

using namespace v8;
Handle<Value> cap::create(const Arguments& args) {//create an image
  HandleScope scope;
    using namespace cimg_library;
    CImg<unsigned char> captcha(256,64,1,3,0);//delete this line run ok!
  return scope.Close(Boolean::New(1));
}
cap::cap(){};
cap::~cap(){};

index.js code:

var obj = require('../build/Release/hcaptha.node');

anyone can help me?

WuZhonghua
  • 331
  • 1
  • 2
  • 9

1 Answers1

2

I finally find the result. add line "libraries":['-lX11'] into the binding.gyp file,that's ok! new binding.gyp file like this:

{
  "targets":[
    {
      "target_name": "hcaptha",
      "sources": [ "addon/hcaptha.cc" ,"addon/cap.cc"],
      "cflags": ['-fexceptions','-O2','-Dcimg_use_png'],
      "cflags_cc": ['-fexceptions','-O2','-Dcimg_use_png'],
      "libraries":['-lX11']
    }
  ]
}
WuZhonghua
  • 331
  • 1
  • 2
  • 9