# Reducing memory size using nostdlib flag

**URL:** <https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178>\
**Category:** LibCyphal\
**Created:** [October 8, 2018, 8:05am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178 "2018-10-08T08:05:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kjell](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/k/5daacb/32.png) [@Kjell](https://forum.opencyphal.org/u/Kjell)\
**Post date:** [October 8, 2018, 8:05am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/1 "2018-10-08T08:05:42Z")

</div>

Hi,

i am trying to get libuavcan working on a stm32f413 on top of stm32cubemx generated code and freertos. The image gets too large after including libuavcan (about 150 kB bigger than without) - like in [https://groups.google.com/forum/#!topic/uavcan/18\_GhJchWX4](https://groups.google.com/forum/#!topic/uavcan/18_GhJchWX4). I therefore used the proposed flags, especially -nostdlib -lc -lgcc plus --specs=nano.specs and -lnosys.  
arm-none-eabi is version is 7.3.1.

I got errors such as “undefined reference to operator” delete/new. In the build\_config i changed the used c++ version for libuavcan from c++11 to c++03 to reduce dynamic memory structures, but following errors remained:  
undefined reference to `std::ios_base::Init::~Init()' in line 74, external location: /usr/arm-none-eabi/include/c++/7.3.1/iostream|C/C++ Problem and undefined reference to`std::ios\_base::Init::Init()’ in line 74, external location: /usr/arm-none-eabi/include/c++/7.3.1/iostream C/C++ Problem.

I would appreciate any hint! Terminal output or makefile i could post if needed.

Best wishes, Kjell

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [October 8, 2018, 8:28am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/2 "2018-10-08T08:28:55Z")

</div>

> I therefore used the proposed flags, especially -nostdlib -lc -lgcc plus --specs=nano.specs and -lnosys.

Probably `nosys` broke the placement new operator? All other flags look correct.

> In the build\_config i changed the used c++ version for libuavcan from c++11 to c++03 to reduce dynamic memory structures

**Libuavcan never uses any dynamic memory** regardless of the build configuration, unless you enable `UAVCAN_TOSTRING`, in which case dynamic memory will be used indirectly via `std::string`. Libuavcan uses the “placement new” operator; so if your environment doesn’t implement it, you can ask the library to provide the implementation for you by enabling `UAVCAN_IMPLEMENT_PLACEMENT_NEW`. See [https://uavcan.org/Implementations/Libuavcan/Tutorials/1.\_Library\_build\_configuration/](https://uavcan.org/Implementations/Libuavcan/Tutorials/1._Library_build_configuration/).

> undefined reference to `std::ios_base::Init::~Init()' in line 74, external location: /usr/arm-none-eabi/include/c++/7.3.1/iostream|C/C++ Problem and undefined reference to` std::ios\_base::Init::Init()’ in line 74, external location: /usr/arm-none-eabi/include/c++/7.3.1/iostream C/C++ Problem.

This looks like you either accidentally enabled `UAVCAN_TOSTRING`, or it got enabled by default by mistake. Consider setting `UAVCAN_TOSTRING=0` and see if it helps.

---

<div class="post-metadata">

**Author:** ![Kjell](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/k/5daacb/32.png) [@Kjell](https://forum.opencyphal.org/u/Kjell)\
**Post date:** [October 8, 2018, 8:44am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/3 "2018-10-08T08:44:37Z")

</div>

Thank you for the fast reply!

UAVCAN\_TOSTRING i left disabled.

Placement new is implemented by the arm-none-eabi libraries. I tried enabling the uavcan provided placement new, but it therefore gave a redefinition error.

Your documentation clearly states that libuavcan does not use dynamic memory, i was just perplex due to the error messages.

Leaving out the inclusion of nosys stubs did not remove the errors.

I could try to set up a completely new project again, and see if it works then

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [October 8, 2018, 8:53am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/4 "2018-10-08T08:53:18Z")

</div>

> UAVCAN\_TOSTRING i left disabled.

I also suggest disabling `UAVCAN_DEBUG` explicitly and see if it helps. Only those two options (debug and to-string) can make use of the heavy string handling logic from the standard library.

---

<div class="post-metadata">

**Author:** ![Kjell](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/k/5daacb/32.png) [@Kjell](https://forum.opencyphal.org/u/Kjell)\
**Post date:** [October 8, 2018, 10:36am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/5 "2018-10-08T10:36:01Z")

</div>

Checked that as well. Still not working. But i added some code for some extra functionality in my projects libuavcan, so i better get a new pure libuavcan to test if i get it working. Though i did not include any string or printing methods, but to be sure. Thank you so far!

---

<div class="post-metadata">

**Author:** ![Kjell](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/k/5daacb/32.png) [@Kjell](https://forum.opencyphal.org/u/Kjell)\
**Post date:** [October 9, 2018, 6:57am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/6 "2018-10-09T06:57:51Z")

</div>

Ok it’s working now with the new source code from github, thank you!

---

<div class="post-metadata">

**Author:** ![Kjell](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/k/5daacb/32.png) [@Kjell](https://forum.opencyphal.org/u/Kjell)\
**Post date:** [October 9, 2018, 7:10am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/7 "2018-10-09T07:10:27Z")

</div>

Hi,

one final question! I downloaded the up to date libuavcan source code from github and there were some file includes in some headers, which did not exist (for instance Timestamp.hpp in time.hpp). There were more of those missing files in include/uavcan/protocol. I just added those files of the old libuavcan i had on my computer.  
But certainly i missed something, can i just remove those includes which do not resolve? Or do i have to download something else?

Thank you for your efforts, best wishes!

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [October 9, 2018, 7:43am UTC](https://forum.opencyphal.org/t/reducing-memory-size-using-nostdlib-flag/178/8 "2018-10-09T07:43:26Z")

</div>

The missing files must be generated from DSDL definitions during the build process by the DSDL compiler (`libuavcan_dsdlc`). If that is not happening, see [https://uavcan.org/Implementations/Libuavcan/FAQ/#build-is-failing-because-of-missing-header-files](https://uavcan.org/Implementations/Libuavcan/FAQ/#build-is-failing-because-of-missing-header-files)
