From mboxrd@z Thu Jan 1 00:00:00 1970 From: To: Claudiu BRASOVEAN Cc: gcc-help@gcc.gnu.org Subject: Re: need help Date: Tue, 02 May 2000 10:00:00 -0000 Message-id: References: <390F02F0.F265AF25@rdscj.ro> X-SW-Source: 2000-05/msg00003.html On Tue, 2 May 2000, Claudiu BRASOVEAN wrote: > Hello.... > > Please excuse my childish question but I am new in the field and I am lost due to a very simple problem. Please note that this list is for questions specific to gcc; your question is a general C question that is not specific to gcc. > Here is my problem: > Main program: > //main.c > #include > #include "funct.h" > > void main(void){ Note: the return type of main() should always be 'int'. > > printf("Calling external function\n"); > > foo(3); > > } > //////////////////// > //funct.h > ..... > extern void foo(int); > ..... > > //////////////////// > //funct.c > #include > #include "funct.h" > .......... > void foo(int x){printf("My parameter was:%d\n",x);}; > .................. > Here is what i get from gcc (in fact is ld, isn't it?) > > /tmp/ccahK6eu1.o: In function `main': > /tmp/ccahK6eu1.o(.text+0x29): undefined reference to `foo' Did you link funct.c with main.c ? You need to do something like this: $gcc funct.c main.c $./a.out or: $gcc -c funct.c $gcc -c main.c $gcc funct.o main.o $./a.out If I compile and link it this way, your code works fine on my i686-linux-pc-gnu box with gcc 2.95.2 > > I do not understand why ld can not resolve symbol. ld can only resolve what it can see. If you do not pass it the name of the module, it will know to look in that module for functions. > The compiling phase works fine > I do have a SuSE 6.3 Linux distribution whith gcc-2.7.2.3-63 on it. > > Thank you in advance. > >