Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Missing functions in math.h (sqrt)
PostPosted: Mon Nov 07, 2011 9:57 pm 
Offline

Joined: Fri Feb 18, 2011 1:56 pm
Posts: 8
I cannot make sqrt() work on my SAM9:

#include <math.h>

// this is working
x = sqrt(10.1);

// none of these are
float a = 10.1;
int b = 10;
x = sqrt(a);
y = sqrt(b);

Similarly pow(x,2) works, but not pow(x,0.5), and it should!
It seems like sqrt and other functions are not defined in the math.h of the atsam toolchain.. but it's weird..

Ideas?


Top
 Profile  
 
 Post subject: Re: Missing functions in math.h (sqrt)
PostPosted: Wed Nov 09, 2011 12:45 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Please define "is not working"

# gcc mathtest.c -omathtest /lib/libm.so.0
# ./mathtest
3.178050
3.178050 3.162278
# cat mathtest.c
#include <stdio.h>

#include <math.h>

int main(int argc, char **argv)
{
float x, y;

// this is working

x = sqrt(10.1);

printf("%f\n", x);

// none of these are

float a = 10.1;

int b = 10;

x = sqrt(a);

y = sqrt(b);

printf("%f %f\n", x, y);
}
# gcc -v
Using built-in specs.
Target: arm-unknown-linux-uclibcgnueabi
Configured with: /home/ct/buildroot-2011.05/output/toolchain/gcc-4.3.5/configure
--prefix=/usr --build=x86_64-unknown-linux-gnu --host=arm-unknown-linux-uclibcg
nueabi --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c,c++ --with-
gxx-include-dir=/usr/include/c++ --disable-__cxa_atexit --enable-target-optspace
--disable-libgomp --with-gnu-ld --disable-libssp --disable-multilib --disable-t
ls --disable-shared --disable-nls --enable-threads --disable-decimal-float --wit
h-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=arm926ej-s -
-with-pkgversion='Buildroot 2011.05' --with-bugurl=http://bugs.buildroot.net/
Thread model: posix
gcc version 4.3.5 (Buildroot 2011.05)

# gcc powtest.c -opowtest /lib/libm.so.0
# ./powtest
151.290005
3.507136
# cat powtest.c
#include <stdio.h>
#include <math.h>

int main(int argc, char **argv)
{
float x = 12.3;
printf("%f\n", pow(x,2));
printf("%f\n", pow(x,0.5));
}


Top
 Profile  
 
 Post subject: Re: Missing functions in math.h (sqrt)
PostPosted: Thu Nov 10, 2011 7:43 pm 
Offline

Joined: Fri Feb 18, 2011 1:56 pm
Posts: 8
I get:
undefined reference to 'sqrt'

I work with CodeBlocks, I compile my code on my Ubuntu 11.10 laptop using the at91sam toolchain (and then I would move the executable file to the board to run it).
I use:
--sysroot=/home/ste/stuffOE/tmp/sysroots/armv5te-angstrom-linux-gnueabi/
in "Other options" in Codeblocks to set the toolchain to use. Then of course I use that toolchain (this is the only issue I have with programming on this board, all other complex programs in C works perfectly so the toolchain is ok I assume).


Top
 Profile  
 
 Post subject: Re: Missing functions in math.h (sqrt)
PostPosted: Thu Nov 10, 2011 9:05 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
>>I get: undefined reference to 'sqrt'

Like this :

# gcc mathtest.c
/tmp/ccWlmasl.o: In function `main':
mathtest.c:(.text+0x60): undefined reference to `sqrt'
mathtest.c:(.text+0x98): undefined reference to `sqrt'
collect2: ld returned 1 exit status

You have failed to link in the math library containing the functions you want.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: