2013-01-15 11 views
0

CImg 라이브러리를 사용하여 node.js에서 이미지를 처리하고 싶으므로 노드 추가 기능을 작성합니다. 컴파일 성공, 나는 노드 - gyp 빌드 commond를 실행, 그건 괜찮아요.node-gyp 오류가있는 CImg 라이브러리를 실행하십시오.

하지만 난 노드 프로그램을 실행하면 다음과 오류가 발생합니다

[[email protected] 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'); 

누구든지 나를 도와 줄 수 있습니까?

답변

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'] 
    } 
    ] 
}