By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

undefined references to functions when linking

P: n/a
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 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
<st*****@yahoo.comschrieb im Newsbeitrag
news:11**********************@j4g2000prf.googlegro ups.com...
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
Jun 12 '07 #2

P: n/a
On Jun 12, 6:13 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
<sten...@yahoo.comschrieb im Newsbeitragnews:11**********************@j4g2000pr f.googlegroups.com...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 '07 #3

P: n/a
<st*****@yahoo.comschrieb im Newsbeitrag
news:11**********************@n15g2000prd.googlegr oups.com...
On Jun 12, 6:13 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
><sten...@yahoo.comschrieb im
Newsbeitragnews:11**********************@j4g2000p rf.googlegroups.com...>
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
Jun 12 '07 #4

P: n/a
st*****@yahoo.com wrote:
>
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.
Failure to link t1.o.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 12 '07 #5

P: n/a
st*****@yahoo.com writes:
On Jun 12, 6:13 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
><sten...@yahoo.comschrieb im Newsbeitragnews:11**********************@j4g2000pr f.googlegroups.com...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.
Jun 13 '07 #6

P: n/a
On Jun 12, 8:55 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
<sten...@yahoo.comschrieb im Newsbeitragnews:11**********************@n15g2000p rd.googlegroups.com...
On Jun 12, 6:13 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
<sten...@yahoo.comschrieb im
Newsbeitragnews:11**********************@j4g2000pr f.googlegroups.com...>
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 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.