Reducing memory size using nostdlib flag

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. 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 tostd::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

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/.

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.

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

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.

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!

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

1 Like

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!

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