Thread: undefined reference to

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    undefined reference to

    I keep getting compile error:

    ../../thread/thread.c:318: undefined reference to `pid_alloc`
    ../../thread/thread.c:350: undefined reference to `pi_get`

    thread.c looks like:
    Code:
    ....
    #include <pid.h>
    ....
    line 318:   assert(pid_alloc(tid));
    ...
    line 350:   struct pidinfo *wait_t = pi_get(tid)
    ...
    pid.h:
    Code:
    struct pidinfo *pi_get(pid_t pid);
    ...
    int pid_alloc(pid_t *retval)
    ...
    pid.c:
    Code:
    ...
    struct pidinfo *
    pi_get(pid_t pid)
    {
    ...
    }
    ...
    int
    pid_alloc(pid_t *reval)
    {
    ...
    }
    ...
    I can't understand why I'm getting this error when pid.h and pid.c seem to be fine

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by shaun84
    I keep getting compile error:

    ../../thread/thread.c:318: undefined reference to `pid_alloc`
    ../../thread/thread.c:350: undefined reference to `pi_get`
    Looks more like a linker error. Are you attempting to link to to proper library?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    found it

    this line is wrong
    Code:
    #include <pid.h>

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    but w/o <pid.h> none of the functions defined in it will work.

  5. #5
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    you obviously don't get what i meant , I'm not saying that line isn't supposed to be there, it's just wrong

    you put "<>" whenever you are reffering to a built in library, whereas when you refer to an external library of your own, you have to use .... (fill in the blanks)
    Last edited by yxunomei; 10-14-2006 at 06:17 AM.

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by yxunomei
    when you refer to an external library of your own, you have to use .... (fill in the blanks)
    i think u can change this sentence to like "when u refer to an external library of your own which is located in the current directory, you have to use ..."

    because even thought if u have your own .h file and when u place it in include directory u will refer that header file using <>

    ssharish2005

  7. #7
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    ah yes, i forgot to include that possibility

    Code:
    #include <thatPossibility.h>

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by yxunomei
    you obviously don't get what i meant , I'm not saying that line isn't supposed to be there, it's just wrong

    you put "<>" whenever you are reffering to a built in library, whereas when you refer to an external library of your own, you have to use .... (fill in the blanks)
    You really don't seem to understand what a library is. Library is not a HEADER file. You INCLUDE header files and you LINK to library files.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  9. #9
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    whoa now dat's a new knowledge for me...

    thank's sir!

  10. #10
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    Thanks for the feedback guys.

    From what I understand you have to use different syntax when referencing headers files that are not in the "include" directory.

    However, I have pid.h along with all my other header files that are "included" in thread.c inside the include folder... therefore all includes are of the form "#include <filename.h>"

    Could there be a problem within my pid.c that causes this?

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    No, I would say that the problem is that you're not linking to the correct library, as Dave_Sinkula said in the first reply of this thread. For GCC, the option might be -lbsd-compat or -lpthread or -lthread or something else entirely. (I'm not sure where those functions are.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    try this

    Code:
    #include "pid.h"
    notice the double quotes

    if that doesn't work, try dwk's suggestion

  13. #13
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Undefined reference IS a linker error.
    You cannot get rid of it by including header files.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM