[uClibc]'rint' is not usable.

Erik Andersen andersen at codepoet.org
Wed Dec 4 16:14:48 UTC 2002


On Wed Dec 04, 2002 at 03:46:47PM +0800, cwang wrote:
> Hi, dear develops:
> 
> When I try to compile the following short program:
> #include <tgmath.h>
> #include <math.h>
> #include <stdlib.h>
> 
> int main(void) {
>     dobule d1, d2;
>     d1 = 0.6;  d2 = rint(d1);
>     printf("d1 = %f, d2 = %f\n", d1, d2);
>     return 0;
> }

You have a few typos...  It should be:

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

int main(void) {
    double d1, d2;
    d1 = 0.6;  d2 = rint(d1);
    printf("d1 = %f, d2 = %f\n", d1, d2);
    return 0;                            
}


> Then I run the following command to build it:
> 
> /usr/i386-linux-uclibc/usr/bin/gcc -o rint-uclibc rint.c

Always use the fully named cross-style gcc... i.e
    
    /usr/i386-linux-uclibc/bin/i386-uclibc-gcc -Wall -Os rint.c -o rint -lm

Otherwise 'gcc' will call 'ld' and link your app with the wrong
C library.  You also forgot to link in the math library.  Be sure
you have built uClibc with DO_C99_MATH enabled, and then it works
just fine.

$ ldd ./rint
        libm.so.0 => /usr/i386-linux-uclibc/lib/libm.so.0 (0x0x40007000)
        libc.so.0 => /usr/i386-linux-uclibc/lib/libc.so.0 (0x0x40015000)
        ld-uClibc.so.0 => /usr/i386-linux-uclibc/lib/ld-uClibc.so.0 (0x0x40000000)
$ ./rint 
d1 = 0.600000, d2 = 0.812500

 -Erik

--
Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--



More information about the uClibc mailing list