LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   red hat 9.0 gcc (ceil, floor and sqrt function errors) ?? (https://www.linuxquestions.org/questions/linux-enterprise-47/red-hat-9-0-gcc-ceil-floor-and-sqrt-function-errors-330254/)

gemini_shooter 06-04-2005 09:15 AM

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;
}


rjlee 06-04-2005 04:23 PM

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


All times are GMT -5. The time now is 12:27 PM.