FAQ
Ok, stuck again. Got everything working with the integer and pointer thing
from all the help before (thanks!) but now I'm stuck in another place. The
source files I have are .C files with .H headers. I can compile them using
node-gyp with no issues and apparently bind them to my .CC file with no
issue.

When I try and actually USE them though I get back an error saying
undefined symbol: <somevalue> where <somevalue> is always _Z11<methodName>v
the _Z11 and v never changes. The <methodName> part is always the name of
the method from the .C file.

I'm guessing this is something really simple, but I don't know enough about
C/CC/whatever to know where I'm screwing up.

Here is a simple example, while this isn't the real code it blows up just
like the real code :)

/* lib.c */
#include lib.h
int test_linked(void){
   return 1;
}

/* lib.h */
#ifndef _LIB_
#define _LIB_
int rest_linked(void);
#endif

/*lib.cc*/
#include <node.h>
#include <v8.h>

#include "lib.h"

using namespace v8;

Handle<Value> Test(const Arguments& args){
   HandleScope scope;
   return scope.Close(Number::New(test_linked()));
}

void init(Handle<Object> exports) {
   exports->Set(String::NewSymbol("test"),
       FunctionTemplate::New(Test)->GetFunction());
}

NODE_MODULE(lib, init)

/* binding.gyp */

{
   "targets": [
     {
       "target_name": "lib",
       "sources": [
         "src/lib.c",
         "src/lib.cc"
       ]
     }
   ]
}

Building with node-gyp rebuild results in all proper .O files put where you
would expect (build/Release/obj.target/lib/src) and the .NODE file going
where it should (build/Release)

Then using:
var lib = require('./build/Release/lib');
lib.test();

Fails with:
node: symbol lookup error: /home/.../build/Release/lib.node: undefined
symbol: _Z11test_linkedv


I know this is something I'd doing wrong, but not sure what. I'm guessing
there is some reference to the .O files missing or they are where they
shouldn't be so when the .NODE file loads it can't find the .O files and
thus can't link the methods.

As always, any help greatly appreciated.

  - Jeremy

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAAhs7EgWnAMob7jn-HpUWS1gjQyTKCKjVHC2utFmjnsc8gF8sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Aria Stewart at Oct 20, 2014 at 8:24 pm

    On Oct 20, 2014, at 4:16 PM, Jeremy Darling wrote:

    Ok, stuck again. Got everything working with the integer and pointer thing from all the help before (thanks!) but now I'm stuck in another place. The source files I have are .C files with .H headers. I can compile them using node-gyp with no issues and apparently bind them to my .CC file with no issue.

    When I try and actually USE them though I get back an error saying undefined symbol: <somevalue> where <somevalue> is always _Z11<methodName>v the _Z11 and v never changes. The <methodName> part is always the name of the method from the .C file.

    I'm guessing this is something really simple, but I don't know enough about C/CC/whatever to know where I'm screwing up.

    Here is a simple example, while this isn't the real code it blows up just like the real code :)

    /* lib.c */
    #include lib.h
    int test_linked(void){
    return 1;
    }

    /* lib.h */
    #ifndef _LIB_
    #define _LIB_
    int rest_linked(void);
    This, here, is being included from both C and C++ -- it will need to add an extern "C" to generate the right symbol from C++ -- in C++, it's _Z11rest_linked; in C, it's _rest_linked. If you declare extern "C" on it, it'll always use the C convention.


    Aria

    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/ECCC2A05-138E-4BEE-A282-C4FCB1691D3C%40nbtsc.org.
    For more options, visit https://groups.google.com/d/optout.
  • Jeremy Darling at Oct 20, 2014 at 8:37 pm
    Nevermind, found my own answer after finally hitting the right google
    search terms.

    Added
    #ifdef __cplusplus
    extern "C" {
    #endif

    ... source code here...

    #ifdef __cplusplus
    }
    #endif

    So that the CPP compiler would know I was talking C and not CPP :)
    On Mon, Oct 20, 2014 at 3:16 PM, Jeremy Darling wrote:

    Ok, stuck again. Got everything working with the integer and pointer
    thing from all the help before (thanks!) but now I'm stuck in another
    place. The source files I have are .C files with .H headers. I can
    compile them using node-gyp with no issues and apparently bind them to my
    .CC file with no issue.

    When I try and actually USE them though I get back an error saying
    undefined symbol: <somevalue> where <somevalue> is always _Z11<methodName>v
    the _Z11 and v never changes. The <methodName> part is always the name of
    the method from the .C file.

    I'm guessing this is something really simple, but I don't know enough
    about C/CC/whatever to know where I'm screwing up.

    Here is a simple example, while this isn't the real code it blows up just
    like the real code :)

    /* lib.c */
    #include lib.h
    int test_linked(void){
    return 1;
    }

    /* lib.h */
    #ifndef _LIB_
    #define _LIB_
    int rest_linked(void);
    #endif

    /*lib.cc*/
    #include <node.h>
    #include <v8.h>

    #include "lib.h"

    using namespace v8;

    Handle<Value> Test(const Arguments& args){
    HandleScope scope;
    return scope.Close(Number::New(test_linked()));
    }

    void init(Handle<Object> exports) {
    exports->Set(String::NewSymbol("test"),
    FunctionTemplate::New(Test)->GetFunction());
    }

    NODE_MODULE(lib, init)

    /* binding.gyp */

    {
    "targets": [
    {
    "target_name": "lib",
    "sources": [
    "src/lib.c",
    "src/lib.cc"
    ]
    }
    ]
    }

    Building with node-gyp rebuild results in all proper .O files put where
    you would expect (build/Release/obj.target/lib/src) and the .NODE file
    going where it should (build/Release)

    Then using:
    var lib = require('./build/Release/lib');
    lib.test();

    Fails with:
    node: symbol lookup error: /home/.../build/Release/lib.node: undefined
    symbol: _Z11test_linkedv


    I know this is something I'd doing wrong, but not sure what. I'm guessing
    there is some reference to the .O files missing or they are where they
    shouldn't be so when the .NODE file loads it can't find the .O files and
    thus can't link the methods.

    As always, any help greatly appreciated.

    - Jeremy
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAAhs7Egx4p5wSojHCSMr%2B0ZM3r9DeteeHy5hbsEDURoKMoX%2BMQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedOct 20, '14 at 8:18p
activeOct 20, '14 at 8:37p
posts3
users2
websitenodejs.org
irc#node.js

2 users in discussion

Jeremy Darling: 2 posts Aria Stewart: 1 post

People

Translate

site design / logo © 2022 Grokbase