Jump to content

Aren't there math and other libraries for c ?


Recommended Posts

I am using Mandriva 2007

I wrote a simple c program :

 

#include <stdio.h>
#include <math.h>
double d,e,f;
main()
{
double a,b,c;
void hesapla(double x,double y,double z);
scanf("%lf",&a);
scanf("%lf",&b);
scanf("%lf",&c);
hesapla(a,b,c);
}
void hesapla(double x,double y,double z)
{

double delta;
delta=y*y-4*x*z;
if(delta==0)
{ d=-y/2*x;
printf("delta 0 %lf",d);
return;
}
else 
{
if(delta>0)
{
d=(-y-(exp(0.5*log(delta)))/2*x);
e=(-y+(exp(0.5*log(delta)))/2*x);
printf("delta>0 %lf %lf",d,e);
return;
}
else
{
printf("yok bi?i");
return;
}
}
}

 

When I use the cc command I take these errors:

 

denklem.c:(.text+0x10c): undefined reference to `log'

denklem.c:(.text+0x11c): undefined reference to `exp'

denklem.c:(.text+0x13b): undefined reference to `log'

denklem.c:(.text+0x14b): undefined reference to `exp'

collect2: ld returned 1 exit status

 

I thought it was because of the panthomime of math library. Why can it be?

Link to comment
Share on other sites

Suppose you have a file with a code you wrote, lets call it "prog.c".

To compile it using GCC, you shuld type in a konsole/terminal emulator the following:

 

gcc -ld [i]/location-of-prog.c[/i] -o [u]name-of-binary[/u]

 

Here how i do it:

 

[ilia@ilia-fc4 ~]$ cd /home/ilia/projects-c

[ilia@ilia-fc4 projects-c]$ ls

a.txt c.txt e.txt HW2.pdf mem.c new out.txt~ tri.c

b.txt d.txt f.txt mem mem.o out.txt tri tri.o

[ilia@ilia-fc4 projects-c]$ gcc -ld mem.c -o mem

[ilia@ilia-fc4 projects-c]$

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...