Gossamer Forum
Home : General : Perl Programming :

c h2lp!

Quote Reply
c h2lp!
Hi everybody,

Could you please help me to get this error over?

Say, I write a very simple c program as below

#include <math.h>
#include <stdio.h>

int main()
{
int i;
i=floor(2.3);
return 0;
}

Then compile by the gcc

gcc -o test test.c

and I always get the error " undefined reference to `floor' "
Frown
Thanks in advance


Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] c h2lp! In reply to
I'm no C programmer, but from your code it looks like that error is absolutely right.

There is no such sub as floor. Maybe you need to define floor somewhere? Because you're calling floor with the arguments 2,3 but where these arguments get passed to are not clear.

- wil
Quote Reply
Re: [Wil] c h2lp! In reply to
Hi Wil,

Thanks for your advise. I'm sure that the floor function is already existed. I have compile with -c option without error. I mean that when gcc link my program, it does not find the implemented floor function which was defined in the math.h file.
Any suggestions?

Regards,


Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] c h2lp! In reply to
Yes floor() is included with math.h but exists in a different file.

Try adding -lm to the gcc command line when linking

Last edited by:

PaulW: Nov 30, 2001, 4:45 AM
Quote Reply
Re: [PaulW] c h2lp! In reply to
Yes, It works.
Thanks Palw. you are a greate c programmer!



Cheers,

Dat

Programming and creating plugins and templates
Blog