Go Down

Topic: Eclipse large HEX file size (Read 10637 times) previous topic - next topic


Hmm, I don't know exactly what Eclipse is doing but it looks like it is precompiling the entire Arduino library. If so, it's likely compiling in all the floating-point support routines just in case they're needed, whereas the Arduino IDE only compiles in what a particular sketch needs.

The Quick Shield: breakout all 28 pins to quick-connect terminals


That could make sense I'll do some testing around it and will include all files direct into a project w/o using a lib.
Keep you posted about the outcome (after my beauty sleep)
I am still wondering if I am the only guy using Eclipse and sees that something is wrong.


Its really touching a lot of files.


I'm seeing the same problem with my shiny new Eclipse/WinAVR installation.  I was going to start a similar thread, and then I saw this one.  I'm anxious to find a solution since I like using the Eclipse environment.



Results of the test:
Included the Arduino lib files into an Eclipse project. Added main.h and main.cpp as above.
Project properties according to the cook book (see post 1)
And voila: the HEX file size increased to 17kB.

I opened a thread in SourceForge to see if they have an idea which switches to set: https://sourceforge.net/projects/avr-eclipse/forums/forum/664382/topic/3844152

In between I tested a good concept idea (but far way to call it beta release) from this gentleman: http://code.google.com/p/avr-project-ide/wiki/Help. Same code, same compilers generate the expected 2.6kB like Arduino IDE.

Keep you posted and still happy for receiving any advice.


Try adding -ffunction-sections and -fdata-sections to the compile flags.

I think this was the right idea, but there's a match set of options that you need to add to the link command.  Ummm:
"-Wl,--gc-sections"   or "--gc-sections" (depending on whether it uses some version of gcc as the linker command, or uses "ld" directly.)

the quoted compiler options cause each function and piece of data to be put in its own linker section.  The linker option causes any sections that aren't reference from some other section to be omitted.  Or something like that.


Thanks,  case closed  :)

the a.m. compiler options sorted it out.



Robert -

Can you post the compiler and linker options that finally solved the problem for you?




Here are the compiler/linker settings in a nutshell. If that is too short then give a shout:

AVR Compiler
* Debugging:             Generate Debugging Info: No debugging info
* Optimization:       Optimization Level: to Size Optimizations
                             Other Optimization: -ffunction-sections -fdata-sections
* All options:      --I"...\Arduino-0019\hardware\arduino\cores\arduino"
                             -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections
                             -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=16000000UL
AVR C++ Compiler
* Debugging:             Generate Debugging Info: No debugging info.
* Optimization:       Optimization Level: Size Optimizations
                             Other Optimization: -ffunction-sections -fdata-sections
* All options:      -I"...\Arduino-0019\hardware\arduino\cores\arduino"
                             -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections
                             -funsigned-char -funsigned-bitfields -fno-exceptions -mmcu=atmega328p -DF_CPU=16000000UL
AVR C++ Linker
* Command:                         avr-gcc
* General:                        Other Arguments: -Wl,--gc-sections
* Command line pattern: ${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}
* All options:                  -Wl,-Map,<your *.map file>,--cref -Wl,--gc-sections -L"<your library path>" -mmcu=atmega328p


Thanks, Robert.  Very much appreciated.  I'll give it a try and see if it also fixes my problem.



Sep 14, 2010, 06:53 am Last Edit: Sep 14, 2010, 06:54 am by JimG Reason: 1
Those settings worked for me as well, but....

I also had to compile/archive a new Arduino libcore.a that had the same optimizations (-ffunction-sections -fdata-sections).  After making a new core library using Eclipse/WinAVR, the HEX file from Eclipse for my sample was actually a few bytes smaller than that created using the Arduino IDE.

I will also pass along a particularly helpful (at least with regard to getting the Eclipse command line settings right) feature of the Arduino IDE:  if you hold the shift key while compiling, the IDE will create a command line listing in the console window.  Using this listing you can duplicate the Arduino environment as closely as you'd like in Eclipse.



I also had to compile/archive a new Arduino libcore.a that had the same optimizations

yeah; seems that very few "make" based compile environments remember to include the makefile itself in the dependency list for targets (is Eclipse actually Make based?  The principle still holds..)

The Arduino IDE rebuilds everything (libraries) whenever you switch boards, and nearly everything (core) for every build.  This is liable to get annoying as there is more to compile, but at least it's "safe."

You can also set "build.verbose" to true in your arduino preferences file, and you'll see the build command listing in your console window all the time...


Hi all,

I have the similar problem:

I tried to setup eclipse to compile arduino project and it's working, but blink sketch built with eclipse is about 10k... a little too big :)

I used the core.a from an arduino ide compilation, is it sufficient or do I have to recompile a new one from eclipse with the same configuration ?

Thanks a lot.

Btw, why are you using eclipse ? Apart from code completion ?  :)

Go Up