|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I am having three files similar to the stucture given below, while i execute my test.c, it show error /test.c:5: undefined reference to `myfunction'. I have included myprogram.h in both the files myprogram.c and test.c. if i comment out the line myfunction from myfunction.h, then it is working properly. Is it multiple definition error? i compile the files as cc -c myprogram.c -o myprogram cc -c test.c -o test cc -o test test.o my Thanks in Advance! /******* myprogram.c *******/ #include "myprogram.h" myfunction() { } /******* myprogram.h *******/ myfunction(); /******** test.c *********/ #include "myprogram.h" int main() { myfunction(); } |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
rayuthar@gmail.com wrote:
> Hi, > > I am having three files similar to the stucture given below, while i > execute my test.c, it show error /test.c:5: undefined reference to > `myfunction'. > I have included myprogram.h in both the files myprogram.c and test.c. > > if i comment out the line myfunction from myfunction.h, then it is > working properly. Is it multiple definition error? > i compile the files as > cc -c myprogram.c -o myprogram > cc -c test.c -o test > cc -o test test.o my > Where's myprogram in the line above? > > /******* myprogram.h *******/ > > myfunction(); > Don't use implicit it return, please. -- Ian Collins. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
rayuthar@gmail.com said:
> Hi, > > I am having three files similar to the stucture given below, while i > execute my test.c, it show error /test.c:5: undefined reference to > `myfunction'. > > I have included myprogram.h in both the files myprogram.c and test.c. > > if i comment out the line myfunction from myfunction.h, then it is > working properly. Is it multiple definition error? No - your code has some issues, but it isn't the showstopper in this case. Rather, it's the way you're invoking the linker. > i compile the files as > cc -c myprogram.c -o myprogram > cc -c test.c -o test > cc -o test test.o my This can't work, for any reasonable definition of "work". I suggest you change it, for the time being, to: cc -c myprogram.c myprogram.o cc -c test.c -o test.o cc -o myprogram test.o myprogram.o <snip> -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Richard Heathfield <rjh@see.sig.invalid> writes:
> rayuthar@gmail.com said: [...] >> i compile the files as >> cc -c myprogram.c -o myprogram >> cc -c test.c -o test >> cc -o test test.o my > > This can't work, for any reasonable definition of "work". > > I suggest you change it, for the time being, to: > > cc -c myprogram.c myprogram.o > cc -c test.c -o test.o > cc -o myprogram test.o myprogram.o You missed the "-o" on the first line. For that matter, the first two commands can be simplified by using the default output file name: cc -c myprogram.c cc -c test.c though the "-o" does show more explicitly what's going on. Note that this is about a particular implementation, not about C. For more details, consult your system's documentation for the "cc" command, or ask in comp.unix.programmer. -- Keith Thompson (The_Other_Keith) <kst-u@mib.org> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Keith Thompson said:
<snip> > You missed the "-o" on the first line. So I did. -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Apr 14, 11:04 pm, Richard Heathfield <r...@see.sig.invalid> wrote:
> Keith Thompson said: > > <snip> > > > You missed the "-o" on the first line. > > So I did. > > -- > Richard Heathfield <http://www.cpax.org.uk> > Email: -http://www. +rjh@ > Google users: <http://www.cpax.org.uk/prg/writings/googly.php> > "Usenet is a strange place" - dmr 29 July 1999 Thanks to everyone! But i found out the problem and fault was mine. i was trying to invoke a static function from another c file! |
|
![]() |
| Outils de la discussion | |
|
|