PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > Link through Header Files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Link through Header Files

Réponse
 
LinkBack Outils de la discussion
Vieux 14/04/2008, 09h21   #1
rayuthar@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Link through Header Files

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();
}
  Réponse avec citation
Vieux 14/04/2008, 09h29   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Link through Header Files

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.
  Réponse avec citation
Vieux 14/04/2008, 09h30   #3
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Link through Header Files

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
  Réponse avec citation
Vieux 14/04/2008, 17h15   #4
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Link through Header Files

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"
  Réponse avec citation
Vieux 14/04/2008, 19h04   #5
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Link through Header Files

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
  Réponse avec citation
Vieux 17/04/2008, 05h59   #6
rayuthar@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Link through Header Files

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!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h13.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10271 seconds with 14 queries