This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

linking doesn't work properly ?!


as-salam alikom everyone,

I have a wierd problem with the GNU compiler, the following code compiles
fine when I compile it using the "g++ foo.c" :

/* cosc.c code */
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("cos(3.14) = %-8.2f\n", cos(3.14));
    return(0);
}

while it gives me this error if I try to compile it using the command 
"gcc cosc.c" :

/tmp/ccCbmYWU.o: In function `main':
/tmp/ccCbmYWU.o(.text+0x19): undefined reference to `cos'
collect2: ld returned 1 exit status

but if I compile it using the following commands it compiles well : 

gcc -c cosc.c
gcc -lm cosc.o

and it also compiles fine if I compile it using the command "gcc -lm cosc.c"

I was wondering if anyone knows why this is happening ?
Thanks in advance...

+-----------------------------------------------------+
| Ahmed El-Mahmoudy				      |
|						      |
|  Web : http://www.geocities.com/CapeCanaveral/9568/ |
|  Snail mail : P.O. Box 10 Saray Elkobba,	      |
|	        Cairo ,Egypt.			      |
|               Postal Code 11712		      |
+-----------------------------------------------------+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]