EmbDev.net

Forum: µC & Digital Electronics math.h (linker) problem.


von Markos (Guest)


Rate this post
useful
not useful
Hi,

so I am having a big problem with math.h, using the log function.

I am programming an msp430f169 using mspgcc with a makefile in Eclipse.
I perform a simple log calculation (lN = log(help);) and include the 
math.h

I searched forums, and I found alot of things about linking libraries 
(e.g. with "-lm") etc. but I seem to have tried everything and nothing 
seems to work...
I added -lm in different places the makefile to no avail.
In the project settings in eclipse, I added the lib and include paths.

This is really bugging me, anyone experienced this or can help me fix 
this?
Please let me know if you need more info.

Thanks alot in advance!!

Mark

von mizch (Guest)


Rate this post
useful
not useful
You say you have a big problem, but (except "with math.h") you don't 
describe it.  Please cite the exact error message, provide some source 
code,  and describe, why you think math.h is the culprit and the 
placement of -lm the solution.

von Markos (Guest)


Rate this post
useful
not useful
well, the code will not compile with the log function included. if I 
comment it out, it compiles. The error message is:

msp430-make all
msp430-gcc  -mmcu=msp430x169  -O1  -c temperature.c
msp430-gcc  -mmcu=msp430x169  -lm -o   TempTest.elf main.o temperature.o 
init.o
temperature.o: In function `buildTemperatureValue':
temperature.c:(.text+0x72): undefined reference to `log'
msp430-make: *** [TempTest.elf] Error 1

and the function where I am using the log:

#define RNTC25  (double)47.0
double rNTC, help, lN;

help=RNTC25/rNTC;                 lN = log(help);

and my big problem is that I can't compile it with the log, and I need 
the log of the value.

thanks

von Andreas (Guest)


Rate this post
useful
not useful
Try moving -lm to the end of the command line:
msp430-gcc -mmcu=msp430x169 -o TempTest.elf main.o temperature.o -lm

von Markos (Guest)


Rate this post
useful
not useful
thanks but that didn't work either:

msp430-make all
msp430-gcc  -mmcu=msp430x169   -o   TempTest.elf main.o temperature.o 
init.o -lm
temperature.o: In function `buildTemperatureValue':
temperature.c:(.text+0x72): undefined reference to `log'
msp430-make: *** [TempTest.elf] Error 1

von mizch (Guest)


Rate this post
useful
not useful
Maybe something about your libm is wrong.  Find your MSP430 libm (if 
you're using something unix-like, try /usr/local/msp430/lib/libm.a or 
the like), cd there, and run

 msp430-nm libm.a | grep log

on it.  (Your 'nm' command might be named somewhat different, and 
probably any 'nm' command of any gcc will do the job.)  I'm assuming 
that even if you're on Windows, a basic set of text tools is available 
(grep).  If not, replace grep by a similar text matching tool which is 
provided by your system.

The above command should spit out some lines containing the string "log" 
in them, one of them will look like

0000000a T log

(the number in the first column is irrelevant for our purpose).

If it doesn't show such a line, your math library is to blame.  But if 
you get such a line, I'm running out of ideas.

von Markos (Guest)


Rate this post
useful
not useful
hello Mizch,

tnanks alot for your answer and help. So I did it and did not see the 
line you mentioned:

C:\mspgcc\msp430\lib>msp430-nm libm.a | grep log
         U __ieee754_logf
         U log1pf
         U __ieee754_logf
         U __ieee754_logf
         U __ieee754_logf
         U log1pf
         U ilogbf
         U __ieee754_logf
sf_log1p.o:
0000055c T log1p
0000002c T log1pf
         U log1pf
ef_log.o:
00000032 T __ieee754_logf
0000002c T logf
sf_logb.o:
00000060 T logb
00000000 T logbf
ef_log10.o:
00000014 T __ieee754_log10f
         U __ieee754_logf
00000008 t log10_2hi
0000000c t log10_2lo
00000156 T log10f
         U __ieee754_logf
sf_ilogb.o:
00000082 T ilogb
00000000 T ilogbf

C:\mspgcc\msp430\lib>


What do you think?
I include math.h in the original file, and link to the library folder 
with math.h in it through the properties/includes path in eclipse. I 
also made a path to libm.a in properties/libraries.
I'm out of ideas and info :)

von mizch (Guest)


Rate this post
useful
not useful
Your math library indeed does not contain a log() function; there's 
simply none in there.  A possible workaround would be to use logf() 
which takes a float instead of a double.

You should check the library's documentation for what it says about 
log().  Maybe there exist different versions and the version you use is 
a stripped-down version which lacks some features of a complete standard 
C math library.  I know nothing about MSP30 libraries, so that's just an 
idea.

In any case: there's nothing wrong with your code or the way you compile 
it, it is your version of libm.a which lacks a log() function.  Either 
use logf() (which is there) or replace your libm.a.

von Markos (Guest)


Rate this post
useful
not useful
Thanks alot, will try it :)

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.