I try to compile some C++ code with <iostream> included. Build output:
.\DEBUG.axf: Error: L6218E: Undefined symbol __fread_bytes_avail (referred from ios.o). .\DEBUG.axf: Error: L6218E: Undefined symbol mbsinit (referred from ios.o). .\DEBUG.axf: Error: L6218E: Undefined symbol wmemmove (referred from ios.o).
Somebody said: It's because microLib does not implement full set of features as ARM library (C standard library). On infocenter.arm.com/.../index.jsp written: The default version of __fread_bytes_avail() fills a buffer by calling fgetc() until either the buffer is filled or EOF is encountered. This means default version exists and implemented. But it is not.
Issue is not new: stackoverflow.com/.../iostream-keil-c-problems developer.mbed.org/.../ST-Nucleo-L152RE-SDCard
While writing this post I've solved problem:
#ifdef __MICROLIB /*__CC_ARM*/ /// To suppress MDK-ARM Linker Error: L6218E: Undefined symbol __fread_bytes_avail (referred from ios.o). size_t __fread_bytes_avail(void * __restrict ptr, size_t count, FILE * __restrict stream) //__attribute__((__nonnull__(1,3))) { return -1; } #include <wchar.h> /// To suppress MDK-ARM Linker Error: L6218E: Undefined symbol mbsinit (referred from ios.o). int mbsinit(const mbstate_t * ps) { return -1; } /// To suppress MDK-ARM Linker Error: L6218E: Undefined symbol mbsinit (referred from ios.o). wchar_t *wmemmove(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n) //__attribute__((__nonnull__(1,2))) { return NULL; } #endif /*__MICROLIB*/ /*__CC_ARM*/
If your program will use this functions, they should be implemented properly. Look at open source stdlib implementations on the internet.
The MicroLib is optimized for small memory size systems and therefore does not support C++. See also: www.keil.com/.../armlib_chr1358938938431.htm
I recommend that you are use the full run-time library instead. Just de-select MicroLib
Hi Reinhard,
I am facing same errors when I add few C++ files in my project, that was building fine before that. So as per your post, I have tried to disable MicroLIB as follows:
1. Open "Option for target" 2. On 'Target' tab, uncheck the 'Use MicroLIB' option in 'Code Generation' section. 3. Then rebuild all target files.
Then I programmed the STM32L152ZD based EVAL board with the generated object code. But the board stops working.
Am I disabling it correctly? Do I need to do anything else?
Please help me here.
Thanks, Dhaval