0

我想使用 CImg 库来处理 node.js 中的图像,所以我编写了一个 node 插件来做到这一点。编译成功,我运行node-gyp build commond,没关系。

但是当我运行节点程序时,出现以下错误:

[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)

binding.gyp 文件是:

{
  "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 代码:

#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 代码:

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

任何人都可以帮助我吗?

4

1 回答 1

2

我终于找到了结果。将“libraries”:['-lX11'] 行添加到 binding.gyp 文件中,没关系!新的 binding.gyp 文件如下:

{
  "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']
    }
  ]
}
于 2013-01-16T01:03:25.577 回答