LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 06-04-2005, 09:15 AM   #1
gemini_shooter
LQ Newbie
 
Registered: May 2005
Posts: 5

Rep: Reputation: 0
red hat 9.0 gcc (ceil, floor and sqrt function errors) ??


hi !

I just recently started working in linux red hat 9.0 to compile my C programs , I am using the gcc command but the program is giving me weird errors and does not recognize the functions ceil(), floor() and sqrt(), I have tried and added most header files like math.h nad stdlib.h along with stdio.h but I keep getting wried errors like :

Quote:
/tmp/ccqz1JFE.o(.text+0xba): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status

The program is as follows
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

Code:
int main()
{
	double i, j, k;
	for(j = 0.0; j < 1.0; j += 0.1)
		printf("%8.1f", j);
	printf("\n");
	for(i = 0.0; i < 10.0; i += 1.0)
	{
		for(j = 0.0; j < 1.0; j += 0.1)
		{
			k = i + j;
			printf("%8.1f", sqrt(k));
		}
		printf("\n");
	}
	return 0;
}
 
Old 06-04-2005, 04:23 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
These are linker errors, not compiler errors; hence the “ld”. You will find these functions in the m (maths) library (/usr/lib/libm.so), and you can make this compile using:
Code:
gcc -lm infile.c outfile
A header file only includes the declaration of a function; you need to link your program against the implementation of the function in order to generate a usable binary.

To find out which header file a function is declared in, just look at its manpage:
Code:
man ceil
 
  


Reply



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
sqrt function lmvent Programming 6 10-20-2005 07:53 PM
How do i install gcc on red hat 9 NRHBasher Linux - Newbie 5 03-11-2004 09:35 PM
sqrt() function IamDaniel Programming 6 08-09-2003 10:24 AM
Mplayer, GCC and Red Hat 7.1 cyrille Linux - Newbie 7 04-26-2002 08:52 AM
Installing gcc 2.95.3 on Red Hat 7.0 Quen Linux - Software 0 09-22-2001 10:58 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 09:18 PM.

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