strtof gets Undefined reference

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

strtof gets Undefined reference

1,274件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mspahr on Wed Jan 29 18:20:13 MST 2014
I started my project with an example from "LPCWare/LPC11xx/Downloads/Software/Sample code bundle for LPC11xx peripherals using NXP LPCXpresso".  The project is USB ROM MSC.  I have built on this base.
I am usinf LPCXpresso V5.2.6 with LPC11U35.
I am trying to use stdlib function strtof.
In the source c file I have #include stdlib.h
The file compiles OK.
The linker gives the error "undefine reference to strtok.

I have checked that the MCU compiler and MCU linker target are set to redlib.
I changed the MCU linker target setting from redlib(none) to redlib(semihost), also tried (nohost).
It still fails.
I noticed under the linker general tab that the box "no startup or default libs" is checked.
I unchecked this and it compiles and links OK, but it has added 24k of code and when run, it gets a hard fault.

Please help.  I need to use several functions from redlib.

Mike
0 件の賞賛
返信
2 返答(返信)

1,122件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Jan 30 02:15:52 MST 2014
strtof() is actually a C99 library function. Redlib is a C90 library implementation with some C99 functions provided. Unfortunately in this case it appears that the Redlib header files have got out of step with the source files - in that strtof() is in the header files, but has not yet actually been implemented. We'll investigate getting this fixed for a future release.

The simplest way to fix your problem in the meantime is to provide a version within your code base thus:

float strtof(const char *str, char **endptr) {
  return (float) strtod(str, endptr);
}


Also you should not untick the "no startup or default libs" box.

Aside
You really should consider upgrading to LPCXpresso 6 (you can install in parallel to your LPCXpresso 5 install if you want)…

http://www.lpcware.com/content/forum/lpcxpresso-latest-release

Note that the latest LPCOpen v2 packages all list the actual version of LPCXpresso they were created/tested against - and ALL assume an LPCXpresso 6 install.

Regards,
LPCXpresso Support
0 件の賞賛
返信

1,122件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Thu Jan 30 02:09:55 MST 2014
strtof is a floating point function.

I think thar your libraries are compiled without support for floating point.

Try to use an integer function instead. Or switch to libraries which are compiled with floating point support (== more code size).
0 件の賞賛
返信