LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 05-29-2004, 06:05 PM   #1
enlight1
Member
 
Registered: Jun 2003
Distribution: Fedora 3
Posts: 82

Rep: Reputation: 15
#include <math.h> does not work


I just did a clean install of Mandrake 10.0 Official. All works fine except when I go to compile a simple c program including math.h. The compile completes and then I get a ld error:

[jerry@localhost practice]$ gcc divide.c -o divide
/home/jerry/tmp/ccKo59RF.o(.text+0x8c): In function `main':
: undefined reference to `sinf'
collect2: ld returned 1 exit status

I first noticed when trying to compile a simple benchmark program and it would not go. Here is code for divide.c. I am just printing the sine of PI.

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

#define LIMIT 1000
#define PI 3.14159

int
main(void)
{
int i, j, result;
float num;
for(i=0;i<LIMIT;i++) {
for(j=1;j<10;j++) {
printf("%d / %d = %d R %d.\n",i,j, i/j, i%j);
}
}
num=sinf(PI);
printf("Thats all folks!\n");
printf("The sin of 1.5 is: %f\n", num);
return(0);
}

any suggestions anyone?
 
Old 05-29-2004, 07:06 PM   #2
rkef
Member
 
Registered: Mar 2004
Location: bursa
Posts: 110

Rep: Reputation: 15
Try
Code:
[jerry@localhost practice]$ gcc -lm divide.c -o divide
... you need to compile it against the math library .
 
Old 05-29-2004, 07:59 PM   #3
enlight1
Member
 
Registered: Jun 2003
Distribution: Fedora 3
Posts: 82

Original Poster
Rep: Reputation: 15
That was it. I have to confess I feel a bit stupido after that one
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
math.h Damicles Programming 9 12-04-2010 05:51 AM
include/linux/types.h and include/linux/posix_types.h kpachopoulos Programming 2 11-26-2005 05:52 AM
ANSI C: Math library making #include unnecessary? olspookishmagus Programming 3 11-01-2005 09:50 AM
my iostream.h include won't work slinky2004 Programming 5 09-20-2005 12:37 AM
c math calculation alaios Programming 3 06-01-2004 01:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration