# Compiling Error when include \<memory\>

**URL:** <https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241>\
**Category:** SDK\
**Tags:** evb-amb82\
**Created:** [May 11, 2022, 5:19am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241 "2022-05-11T05:19:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mstsai](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mstsai](https://forum.amebaiot.com/u/mstsai)\
**Post date:** [May 11, 2022, 5:19am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241/1 "2022-05-11T05:19:38Z")

</div>

Not sure if this problem has been reported. I wrote a simple class,

File.h

```auto
#ifndef FS_H
#define FS_H
#undef min
#undef max
#include <memory>
class File
{
public:
    File() {
        _info = 0;
    }
    int getInfo(void);
protected:
    int _info;
};
#endif

```

and File.cpp

```auto
#include "File.h"

int File::getInfo() {
  return _info;
}

```

The Arduino ino file,

```auto
#include "File.h"

File f;
void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

```

I got tons of compile errors (too many lines, I just copied some lines from Arduino console)

```auto
/home/ubuntu/.arduino15/packages/realtek/tools/ameba_d_asdk_toolchain/1.0.1/arm-none-eabi/include/c++/6.5.0/bits/basic_string.h: In function 'std:: __cxx11::string std::__ cxx11::to_string(long double)':
/home/ubuntu/.arduino15/packages/realtek/tools/ameba_d_asdk_toolchain/1.0.1/arm-none-eabi/include/c++/6.5.0/bits/basic_string.h:5538:45: error: '_rtl_vsnprintf' is not a member of 'std'
     return __gnu_cxx::__ to_xstring<string>(&std::vsnprintf, __n,
                                             ^~~

from /home/ubuntu/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/libraries/OOP/src/File.h:7,
from /home/ubuntu/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/libraries/OOP/src/File.cpp:1:
/home/ubuntu/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/system/component/soc/realtek/amebad/fwlib/include/rtl8721d_ram_libc.h:18:12: note: '_rtl_vsnprintf'
 extern int _rtl_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
            ^ ~~~~~~~~~~~~~
exit status 1

```

The ino file shows below compiles without any problem!!

```auto
#undef min
#undef max
#include <memory>

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

```

Environment:Ubuntu 20.04, Arduino 1.8.19. Ameba SDK 3.1.2  
Two boards are installed in the Board Manager, Arduino AVR Board and AmebaD ARM (32-bits) Boards.

I have also modified Arduino.h and un-comment the 28th line so the line looks like,

#define Arduino\_STD\_PRINTF

Any suggestion/comment ?

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [May 11, 2022, 7:24am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241/2 "2022-05-11T07:24:01Z")

</div>

@mstsai

To speed up code and save memory space, some of the GCC standard functions (printf, sprintf …) are replaced with speed optimized ROM code through `#defines`, which can be identified by the `_rtl_` prefix. These defines are probably causing conflicts when code in `<memory>` calls GCC standard functions. Refer to [AN0400 Application Note](https://www.amebaiot.com/en/sdk-download-manual-8722dm/) chapter 5 for details on which functions are replaced and instructions on how to choose to compile in GCC standard library functions.

is there a specific reason you are including `<memory>`?

To compile in the GCC standard library, `#define Arduino_STD_PRINTF` by itself is not sufficient. At minimum you will also need to modify [platform\_stdlib\_rtl8721d.h](https://github.com/ambiot/ambd_arduino/tree/dev/Ameba_misc/TensorFlowLite_patch/patch/system/component/common/api/platform). I have tested with this and it compiles fine.

---

<div class="post-metadata">

**Author:** ![mstsai](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mstsai](https://forum.amebaiot.com/u/mstsai)\
**Post date:** [May 12, 2022, 3:48am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241/3 "2022-05-12T03:48:50Z")

</div>

Thanks for the response. I need to use smart pointer which is defined in , I think. I also need to include for function pointer, although I think I can use traditional function pointer instead.  
For modification of platform\_stdlib\_rtl8721d.h, could you please be more specific? I checked the file. The locations which are related to the errors I got are

```auto
#ifndef STD_PRINTF
        #define printf _rtl_printf
        #define sprintf _rtl_sprintf
        #define snprintf _rtl_snprintf // NULL function
        #define vsnprintf _rtl_vsnprintf
        #define sscanf _rtl_sscanf //if use sscanf in std libc.a, please delete _strtol_r symbol in rlx8721d_rom_symbol_acut.ld
#endif

```

What do I suppose to do for these statements?

---

<div class="post-metadata">

**Author:** ![mstsai](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mstsai](https://forum.amebaiot.com/u/mstsai)\
**Post date:** [May 12, 2022, 4:49am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241/4 "2022-05-12T04:49:34Z")

</div>

Instead of modifying the codes according to AN0400 , I comment the whole section between #ifndef STD\_PRINTF and #endif. Now, it compiles without error. So, I am using the standard library rather than the optimized codes for Ameba, right?

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [May 12, 2022, 5:56am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241/5 "2022-05-12T05:56:58Z")

</div>

yes, without the defines, the functions will not be replaced.

---

<div class="post-metadata">

**Author:** ![mstsai](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mstsai](https://forum.amebaiot.com/u/mstsai)\
**Post date:** [May 13, 2022, 3:05am UTC](https://forum.amebaiot.com/t/compiling-error-when-include-memory/1241/6 "2022-05-13T03:05:05Z")

</div>

An easier solution  
Uncomment  
#define STD\_PRINTF  
at line 5 of /platform\_stdlib\_rtl8721d.h.
