1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

A question for you C++ heads out there

Discussion in 'BBS Hangout' started by paikj83, Feb 21, 2006.

Tags:
  1. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    I'm getting an "undefined reference to errno" linking error. This problem likely stems from linking to the library I've been working on. The odd thing is that when I build the library as static, other programs are able to link without that problem occuring. It's only when I decide to build it as a shared library. I've been able to get away with leaving it static, but eventually I'll have to make the change.

    I've searched Google like a madman, and none of the remedies seem to apply. My library itself doesn't ever make use of errno, although it does make use of another library which uses errno. I really don't see any other explanation, but even if that's the case, I've still no clue how to go about fixing this.

    So any ideas? I'll provide more info as needed. Thanks.
     
  2. xcomputerman

    xcomputerman Contributing Member

    Joined:
    Jan 5, 2006
    Messages:
    781
    Likes Received:
    0
  3. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    It looks like Red Hat Enterprise Linux 3.
     
  4. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    either you've not declared something in your prototypes, or in your <include> files. :( Capture the screen or the error from the terminal window, and post... we really need the EXACT error. We might be able to google it differently.
     
  5. xcomputerman

    xcomputerman Contributing Member

    Joined:
    Jan 5, 2006
    Messages:
    781
    Likes Received:
    0
    Check your LDFLAGS/linker flags. Make sure you have -L/path/to/dir (dir that contains library.la). Something has to be wrong there -- your compiler isn't finding the .la file necessary to link in your library. Are you using libtool?
     
  6. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    Heh, I doubt they'd let me post anything from the terminal. Here's the error message I get:

    /dir/libname/.libs/libname.so: undefined reference to 'errno'
    collect2: ld returned 1 exit status

    I changed the name, because I'm not sure how stringent they are in terms of confidentiality, but the essence of the problem remains. I had tried an #include <cerrno> in my library classes, but they don't seem to have any effect. =T
     
  7. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    The flags seem to be fine. It points to the directory containing my .la file. And yeah, we're using autotools. (That guy has libtool in it, right?)
     
  8. xcomputerman

    xcomputerman Contributing Member

    Joined:
    Jan 5, 2006
    Messages:
    781
    Likes Received:
    0
    autocrap doesn't necessarily include libtool. One way to tell is if your autogen.sh file contains "libtoolize" in it, or there's an ltmain.sh inside the directory.

    Anyways ... my limited research of this seems to indicate that "errno" is either a pthread thing or a glibc thing. I also did some grepping around on my system and it seems that symbol is only seen in static libraries for some reason (which would explain why it works for you when you link statically). You could probably get away with declaring "static int errno" as a global in your code somewhere, or otherwise try to find references to errno in your source code and eliminate them.
     
  9. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    OK. It seems odd that it wouldn't come with libtool, because automake, autoconf, and libtool seem to be bundled together in autotools. But that's neither here nor there. And for the record, we do, in fact, use all three.

    Like I said, my library doesn't make use of errno, so there is no reference to remove. I do make use of another library that uses errno, which is why the static call failed (redeclaration). The library that does have errno is compiled as a shared one and used extensively throughout the system without any problem. There has to be something I'm missing. Any other ideas? :(

    *sigh* I may have to come back to this at a later time.
     
  10. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    I'd NEVER EVER thought I'd say this but this thread is TOO GEEKY even for me. :eek: :D :(
     
  11. xcomputerman

    xcomputerman Contributing Member

    Joined:
    Jan 5, 2006
    Messages:
    781
    Likes Received:
    0
    By the way do you have #include <errno.h> defined? I'm looking at it right now and it does define errno:

    Code:
    /* Declare the `errno' variable, unless it's defined as a macro by
       bits/errno.h.  This is the case in GNU, where it is a per-thread
       variable.  This redeclaration using the macro still works, but it
       will be a function declaration without a prototype and may trigger
       a -Wstrict-prototypes warning.  */
    #ifndef errno
    extern int errno;
    #endif
    You might also want to try linking in pthreads as well, in case the library you're talking about makes use of threads.
     
  12. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    Yeah, I'm thinking <cerrno> is pretty much the same as <errno.h>. Or so they claim. ;) But that didn't do anything. The other library does make use of threads, although the portions I use don't. Does this still require linking of pthreads?
     
  13. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    I'm not sure you wanted that :( at the end. Unless you're one of those sickos that gets off at being as geeky as possible around people you know. Not like I'd do anything like that... Err... No? :p Guess not.
     
  14. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    LOL! Nice comeback. I give you that. I am coming from the "I am cool because I develop Web Stuff, I don't program C++ for a living" school... I guess that's what I meant. Not that you C++-for-a-living dudes aren't cool, though. :D

    I mean, here we are discussing LINKED LIBRARIES, INCLUDE FILES, STATIC CALLS, etc... all in the ROCKETS' FORUM? :D It made me laugh for a bit, but it's cool we all talk about all sorts of trades in this BBS. Just another example of the "diversity" only we members of CF can enjoy. ;)
     
  15. xcomputerman

    xcomputerman Contributing Member

    Joined:
    Jan 5, 2006
    Messages:
    781
    Likes Received:
    0
    I would say linking pthreads is a good idea. I suspect pthreads is what is looking for the errno symbol (or rather, the linker is looking for it because pthreads uses it) ... but that's just speculation from me. Won't know unless you try it out.

    Yeah...funny you'd find this sort of thread on ClutchFans. :)
     
  16. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    Bah. That didn't work either. :( Well, I guess it'll go on hold for now. Thanks for the help. Feel free to drop me a PM if you have other ideas and don't feel like resurrecting this thread in the future. ;)
     
  17. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    PM is disabled. Did you mean IM?
     
  18. paikj83

    paikj83 Contributing Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    Oh... um... I guess email or IM would work fine. :D
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now