Luís Miranda | 22 Jun 11:57 2013
Picon

Undefined symbol on node.js addon

I'm trying to create some node.js addons. Inside the addon i have a call to a static lib. Everything compiles ok, but when i call my addon function from javascript, i get the following:


    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 addon code is the following:

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


Can someone help? 

Thanks


--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Fedor Indutny | 22 Jun 12:07 2013

Re: Undefined symbol on node.js addon


On Sat, Jun 22, 2013 at 11:57 AM, Luís Miranda <luistm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
ctest1

Where is ctest1 declared?

Cheers,
Fedor.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Luís Miranda | 22 Jun 12:40 2013
Picon

Re: Undefined symbol on node.js addon

ctest1 is defined in static lib in the same directory. 

On Saturday, June 22, 2013 11:07:02 AM UTC+1, Fedor Indutny wrote:


On Sat, Jun 22, 2013 at 11:57 AM, Luís Miranda <lui...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
ctest1

Where is ctest1 declared?

Cheers,
Fedor.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Ben Noordhuis | 22 Jun 12:10 2013
Picon

Re: Undefined symbol on node.js addon

On Sat, Jun 22, 2013 at 11:57 AM, Luís Miranda <luistm@...> wrote:
> I'm trying to create some node.js addons. Inside the addon i have a call to
> a static lib. Everything compiles ok, but when i call my addon function from
> javascript, i get the following:
>
>
>     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 addon code is the following:
>
>     #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)
>
>
> Can someone help?
>
> Thanks
>
> (http://stackoverflow.com/questions/17249378/undefined-symbol-on-node-js-addon)

Where is ctest1 defined?  And more importantly: how?

It currently has C++ linkage (hence the mangled name.)  If it's a
symbol from a C library, declare it with `extern "C"`.

You mention it's a static library.  Have you verified that the symbol
actually gets compiled into the .node file?  `nm file.node | grep
ctest1` should print the symbol name, prefixed by a T or t.

-- 
--

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@...
To unsubscribe from this group, send email to
nodejs+unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@...
For more options, visit https://groups.google.com/groups/opt_out.

Luís Miranda | 22 Jun 12:41 2013
Picon

Re: Undefined symbol on node.js addon

I was missing extern "C". Thanks for helping.

On Saturday, June 22, 2013 11:10:26 AM UTC+1, Ben Noordhuis wrote:

On Sat, Jun 22, 2013 at 11:57 AM, Luís Miranda <lui...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> I'm trying to create some node.js addons. Inside the addon i have a call to
> a static lib. Everything compiles ok, but when i call my addon function from
> javascript, i get the following:
>
>
>     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 addon code is the following:
>
>     #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)
>
>
> Can someone help?
>
> Thanks
>
> (http://stackoverflow.com/questions/17249378/undefined-symbol-on-node-js-addon)

Where is ctest1 defined?  And more importantly: how?

It currently has C++ linkage (hence the mangled name.)  If it's a
symbol from a C library, declare it with `extern "C"`.

You mention it's a static library.  Have you verified that the symbol
actually gets compiled into the .node file?  `nm file.node | grep
ctest1` should print the symbol name, prefixed by a T or t.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gmane