2013-06-22 13 views
5

Bazı node.js eklentileri oluşturmaya çalışıyorum. Addon içinde bir statik lib için bir çağrı var. Her şey tamam derler, ama javascript benim eklenti işlevini çağırdığınızda, ben şu olsun:node.js addon'da tanımlı sembol addon

#include <iostream> 
#include <string.h> 
#include <stdlib.h> 

#include <node.h> 
#include <v8.h> 

using namespace v8; 
using namespace std; 

void ctest1(int *); 

Handle<Value> setPort(const Arguments& args){ 
HandleScope scope; 

if (args.Length() != 1) { 
    ThrowException(Exception::TypeError(String::New("Wrong number of arguments."))); 
    return scope.Close(Undefined()); 
} 

// ========================= 
printf("Calling static lib...\n"); 
int x=0; 
ctest1(&x); 
printf("Val c=%d\n", x); 
// ========================= 

return scope.Close(Number::New(args[0]->NumberValue())); 
} 

void Init(Handle<Object> exports) { 
exports->Set(String::NewSymbol("show"), FunctionTemplate::New(setPort)->GetFunction()); 
} 

NODE_MODULE(addon, Init) 

Biri yardım edebilir:

module.js:356 
    Module._extensions[extension](this, filename); 
         ^
Error: /home/.../Projects/NodeAddonComLibTest/build/Debug/addon.node: undefined symbol: _Z6ctest1Pi 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Module.require (module.js:364:17) 
    at require (module.js:380:17) 
    at Object.<anonymous> (/home/.../Projects/NodeAddonComLibTest/doTest.js:1:75) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 

My eklenti kod şudur?

Teşekkür

cevap

6

geçersiz ctest1 (int *); extern "C":

extern "C" { 
    void ctest1(int *); 
} 
ile bildirilmelidir.