Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:34:44+00:00 2026-06-12T21:34:44+00:00

I am trying to create a baremetal c++ application for a cortex-M4 device. My

  • 0

I am trying to create a baremetal c++ application for a cortex-M4 device. My toolchain is ARM-GCC

I have noticed that the code size has shot up by 300kb which is 30% of the available flash size. There is a whole truckload of stuff from the standard libraries that gets linked in bloating TEXT, DATA and BSS areas.

Can this be reduced?

The application is the venerable blinky program with a :
– Blinky.c containing the C routine to toggle a port pin in a while loop
– Main.cpp containing the main() and a simple class with a constructor
– Device startup file which does program loading and yields control to main()

The c file is compiled using gcc while the cpp is compiled using g++. The linker is invoked via g++ to automatically link in stdlibc++(with the assumption that only necessary object fies from the stdlibc++ will be linked in).

I even have -fno-rtti and -fno-exceptions as compile options to g++, but the savings are a pittiance.

By the way, the generated binary works file.

This is the Main.cpp

 #include <iostream>

 using namespace std;

 extern "C" void Toggle_Pin(uint8_t Speed);

 void *__dso_handle = (void *)NULL;
 void __cxa_atexit(void (*Arg)(void *), void *Arg2, void *Arg3){}
 void  __cxa_guard_acquire(void){}
 void  __cxa_guard_release(void){}
 void  __aeabi_atexit(void (*Arg)(void *), void *Arg2, void *Arg3){}

 class Computer
 {
   public:
uint32_t aa;
uint32_t bb;

Computer();
 };

 Computer::Computer()
  {
    aa=0;
    bb=0;
    for(uint8_t i=0;i < 10; i++)
    {
     Toggle_Pin((uint8_t)100);
    }
  }

 Computer a;

 int main(void)
  {
    a.aa = 10;
    Toggle_Pin();
  }

And these are my compilation options provided to g++.

 -O0 -ffunction-sections -Wall -fno-rtti -fno-exceptions -mfloat-abi=softfp -Wa,-adhlns="$@.lst" -c -fmessage-length=0 -mfpu=fpv4-sp-d16 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d) $@" -mcpu=cortex-m4 -mthumb -g3 -gdwarf-2 -o "$@" "$<"

Linker options provided to g++:

 -T LinkerScript.ld" -nostartfiles -L"Path to libraries" -Wl,-Map,"Project.map" -mcpu=cortex-m4 -mthumb -g3 -gdwarf-2 -o "Project.elf" "@makefile.rsp" $(USER_OBJS) $(LIBS)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:34:45+00:00Added an answer on June 12, 2026 at 9:34 pm

    Remove part with

    #include <iostream>
    using namespace std;
    

    you don’t need it. I guess it adds extra global objects / variables and might leave some definitions in binary.

    Also use -Os

    -Os

    Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying create a small web application that allows a user to login
I'm trying create simple application in C++. This application has to read from file
I'm trying to create a Temp Table that has a key field that auto
I am trying create a xmldocument object by a different XML see the code
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying create a RCP Application with Eclipse, but I can't get past the
I'm trying create a box in my Django app that displays text (and possibly
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
Trying to create a simple document that gets the parentNode then applies a background
Trying to create a pattern that matches an opening bracket and gets everything between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.