【问题标题】:Run CImg library with node-gyp error运行带有 node-gyp 错误的 CImg 库
【发布时间】:2012-12-29 04:53:37
【问题描述】:

我想使用 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');

谁能帮帮我?

【问题讨论】:

    标签: node.js add-on cimg node-gyp


    【解决方案1】:

    我终于找到了结果。 将“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']
        }
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-07
      • 2018-03-28
      • 1970-01-01
      • 2013-04-19
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多