undefined references to functions when linking

Discussion in 'C Programming' started by stenasc@yahoo.com, Jun 12, 2007.

  1. Guest

    Hi,

    In a file test1.c, in have the two functions f1 and f2. These are
    declared in the header file t1.h. I want to call these functions in
    another file subprog.c, which contains the function call_funcs. I have
    included the header file t1.h in subprog.c. Using gcc, I can compile
    and get subprog.o without any problems.

    However, when I try to link subprog.o into the main application, I get
    the errors

    In function call_funcs undefined reference to f1
    In function call_funcs undefined reference to f2

    Anybody have any idea what could be causing this.

    Many Thanks
    Bob
    , Jun 12, 2007
    #1
    1. Advertising

  2. <> schrieb im Newsbeitrag
    news:...
    > Hi,
    >
    > In a file test1.c, in have the two functions f1 and f2. These are
    > declared in the header file t1.h. I want to call these functions in
    > another file subprog.c, which contains the function call_funcs. I have
    > included the header file t1.h in subprog.c. Using gcc, I can compile
    > and get subprog.o without any problems.
    >
    > However, when I try to link subprog.o into the main application, I get
    > the errors
    >
    > In function call_funcs undefined reference to f1
    > In function call_funcs undefined reference to f2
    >
    > Anybody have any idea what could be causing this.

    You need to compile test1.c too and link the resulting .o with the
    subprog.o.

    Bye, Jojo
    Joachim Schmitz, Jun 12, 2007
    #2
    1. Advertising

  3. Guest

    On Jun 12, 6:13 pm, "Joachim Schmitz" <>
    wrote:
    > <> schrieb im Newsbeitragnews:...> Hi,
    >
    > > In a file test1.c, in have the two functions f1 and f2. These are
    > > declared in the header file t1.h. I want to call these functions in
    > > another file subprog.c, which contains the function call_funcs. I have
    > > included the header file t1.h in subprog.c. Using gcc, I can compile
    > > and get subprog.o without any problems.

    >
    > > However, when I try to link subprog.o into the main application, I get
    > > the errors

    >
    > > In function call_funcs undefined reference to f1
    > > In function call_funcs undefined reference to f2

    >
    > > Anybody have any idea what could be causing this.

    >
    > You need to compile test1.c too and link the resulting .o with the
    > subprog.o.
    >
    > Bye, Jojo


    Thanks Jojo...that fixed it...I now get multiple definition
    errors...you don't know how to solve that???
    , Jun 12, 2007
    #3
  4. <> schrieb im Newsbeitrag
    news:...
    > On Jun 12, 6:13 pm, "Joachim Schmitz" <>
    > wrote:
    >> <> schrieb im
    >> Newsbeitragnews:...>
    >> Hi,
    >>
    >> > In a file test1.c, in have the two functions f1 and f2. These are
    >> > declared in the header file t1.h. I want to call these functions in
    >> > another file subprog.c, which contains the function call_funcs. I have
    >> > included the header file t1.h in subprog.c. Using gcc, I can compile
    >> > and get subprog.o without any problems.

    >>
    >> > However, when I try to link subprog.o into the main application, I get
    >> > the errors

    >>
    >> > In function call_funcs undefined reference to f1
    >> > In function call_funcs undefined reference to f2

    >>
    >> > Anybody have any idea what could be causing this.

    >>
    >> You need to compile test1.c too and link the resulting .o with the
    >> subprog.o.
    >>
    >> Bye, Jojo

    >
    > Thanks Jojo...that fixed it...I now get multiple definition
    > errors...you don't know how to solve that???

    Not without seeing the code...

    Bye, Jojo
    Joachim Schmitz, Jun 12, 2007
    #4
  5. writes:

    > On Jun 12, 6:13 pm, "Joachim Schmitz" <>
    > wrote:
    >> <> schrieb im Newsbeitragnews:...> Hi,
    >>
    >> > In a file test1.c, in have the two functions f1 and f2. These are
    >> > declared in the header file t1.h. I want to call these functions in
    >> > another file subprog.c, which contains the function call_funcs. I have
    >> > included the header file t1.h in subprog.c. Using gcc, I can compile
    >> > and get subprog.o without any problems.

    >>
    >> > However, when I try to link subprog.o into the main application, I get
    >> > the errors

    >>
    >> > In function call_funcs undefined reference to f1
    >> > In function call_funcs undefined reference to f2

    >>
    >> > Anybody have any idea what could be causing this.

    >>
    >> You need to compile test1.c too and link the resulting .o with the
    >> subprog.o.

    >
    > Thanks Jojo...that fixed it...I now get multiple definition
    > errors...you don't know how to solve that???


    A wild guess: t1.h defines (rather than declares) one or more global
    variables. I.e. you have "int x;" rather than "extern int x;" in
    t1.h. If this is the problem, you need to use the extern form in the
    ..h file and ensure that only one (you get to chose) compilation unit
    contains the actual definition.

    --
    Ben.
    Ben Bacarisse, Jun 13, 2007
    #5
  6. Guest

    On Jun 12, 8:55 pm, "Joachim Schmitz" <>
    wrote:
    > <> schrieb im Newsbeitragnews:...
    >
    >
    >
    > > On Jun 12, 6:13 pm, "Joachim Schmitz" <>
    > > wrote:
    > >> <> schrieb im
    > >> Newsbeitragnews:...>
    > >> Hi,

    >
    > >> > In a file test1.c, in have the two functions f1 and f2. These are
    > >> > declared in the header file t1.h. I want to call these functions in
    > >> > another file subprog.c, which contains the function call_funcs. I have
    > >> > included the header file t1.h in subprog.c. Using gcc, I can compile
    > >> > and get subprog.o without any problems.

    >
    > >> > However, when I try to link subprog.o into the main application, I get
    > >> > the errors

    >
    > >> > In function call_funcs undefined reference to f1
    > >> > In function call_funcs undefined reference to f2

    >
    > >> > Anybody have any idea what could be causing this.

    >
    > >> You need to compile test1.c too and link the resulting .o with the
    > >> subprog.o.

    >
    > >> Bye, Jojo

    >
    > > Thanks Jojo...that fixed it...I now get multiple definition
    > > errors...you don't know how to solve that???

    >
    > Not without seeing the code...
    >
    > Bye, Jojo- Hide quoted text -
    >
    > - Show quoted text -


    Hi All,

    Got it sorted...had to rename a few functions and that cleared
    everything up.

    Many Thanks to all that replied

    Bob
    , Jun 13, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RU
    Replies:
    2
    Views:
    7,967
  2. Igor
    Replies:
    13
    Views:
    2,072
    Roger Leigh
    Dec 11, 2003
  3. Replies:
    5
    Views:
    2,805
    Lars Uffmann
    Aug 21, 2006
  4. Manuel T
    Replies:
    2
    Views:
    617
    Manuel T
    Mar 29, 2007
  5. yeah
    Replies:
    1
    Views:
    433
    Victor Bazarov
    Dec 4, 2007
Loading...

Share This Page