undefined references to functions when linking

S

stenasc

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
 
J

Joachim Schmitz

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
 
S

stenasc

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???
 
B

Ben Bacarisse

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.
 
S

stenasc

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top