HUGE size difference - Makefile vs. Eclipse

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks,

I'm just starting to work with Eclipse IDE and the avr-eclipse plugin this week. I have a project that I started just working with a text editor (kate on linux) and a makefile written by Jorg. I find a huge size disparity between the .hex kicked out by Jorg's makefile and the one kicked out by eclipse.

Jorg's makefile .hex size: 6288 byes
Exlipse .hex size: 9124 bytes

Obviously this is not an acceptable size loss. Any idea what I should do to curb the programming space loss when I compile with eclipse? Both makefiles attached.

Thanks!

Jorg's makefile make output:

make
set -e; avr-gcc -MM -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=box_game.lst  -std=gnu99 box_game.c \
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > box_game.d; \
	[ -s box_game.d ] || rm -f box_game.d
set -e; avr-gcc -MM -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=3595_LCD.lst  -std=gnu99 3595_LCD.c \
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > 3595_LCD.d; \
	[ -s 3595_LCD.d ] || rm -f 3595_LCD.d
set -e; avr-gcc -MM -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99 main.c \
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > main.d; \
	[ -s main.d ] || rm -f main.d

-------- begin --------
avr-gcc (GCC) 4.3.0
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: main.c
avr-gcc -c -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99 main.c -o main.o

Compiling: 3595_LCD.c
avr-gcc -c -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=3595_LCD.lst  -std=gnu99 3595_LCD.c -o 3595_LCD.o

Compiling: box_game.c
avr-gcc -c -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=box_game.lst  -std=gnu99 box_game.c -o box_game.o

Linking: main.elf
avr-gcc -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o  -std=gnu99 main.o 3595_LCD.o box_game.o   --output main.elf -Wl,-Map=main.map,--cref -lm

Creating load file for Flash: main.hex
avr-objcopy -O ihex -R .eeprom main.elf main.hex

Creating load file for EEPROM: main.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
	--change-section-lma .eeprom=0 -O ihex main.elf main.eep
avr-objcopy: --change-section-lma .eeprom=0x00000000 never used

Creating Extended Listing: main.lss
avr-objdump -h -S main.elf > main.lss

Creating Symbol Table: main.sym
avr-nm -n main.elf > main.sym

Size after:
main.elf  :
section     size      addr
.data         34   8388864
.text       6254         0
.bss          37   8388898
.stab      17832         0
.stabstr    5353         0
Total      29510



Errors: none
-------- end --------

Eclipse makefile output:

**** Build of configuration Release for project box_game2 ****

make all 
Building file: ../3595_LCD.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -std=gnu99 -mmcu=atmega168 -DF_CPU=8000000UL -MMD -MP -MF"3595_LCD.d" -MT"3595_LCD.d" -c -o"3595_LCD.o" "../3595_LCD.c"
Finished building: ../3595_LCD.c
 
Building file: ../box_game.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -std=gnu99 -mmcu=atmega168 -DF_CPU=8000000UL -MMD -MP -MF"box_game.d" -MT"box_game.d" -c -o"box_game.o" "../box_game.c"
Finished building: ../box_game.c
 
Building file: ../main.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -std=gnu99 -mmcu=atmega168 -DF_CPU=8000000UL -MMD -MP -MF"main.d" -MT"main.d" -c -o"main.o" "../main.c"
Finished building: ../main.c
 
Building target: box_game2.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,box_game2.map -mmcu=atmega168 -o"box_game2.elf"  ./3595_LCD.o ./box_game.o ./main.o   
Finished building target: box_game2.elf
 
Invoking: AVR Create Extended Listing
avr-objdump -h -S box_game2.elf  >"box_game2.lss"
Finished building: box_game2.lss
 
Create Flash image (ihex format)
avr-objcopy -R .eeprom -O ihex box_game2.elf  "box_game2.hex"
Finished building: box_game2.hex
 
Create eeprom image (ihex format)
avr-objcopy -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex box_game2.elf  "box_game2.eep"
Finished building: box_game2.eep
 
Invoking: Print Size
avr-size --format=berkeley -t box_game2.elf
   text	   data	    bss	    dec	    hex	filename
   8826	    298	     37	   9161	   23c9	box_game2.elf
   8826	    298	     37	   9161	   23c9	(TOTALS)
Finished building: sizedummy

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Jorg's makefile-
# -lm = math library
LDFLAGS += -lm

Linking: main.elf
avr-gcc -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o  -std=gnu99 main.o 3595_LCD.o box_game.o   --output main.elf -Wl,-Map=main.map,--cref -lm 

notice the -lm on the command line.

Eclipse makefile-
LIBS (unable to actually tell what this is set to)

Building target: box_game2.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,box_game2.map -mmcu=atmega168 -o"box_game2.elf"  ./3595_LCD.o ./box_game.o ./main.o   
Finished building target: box_game2.elf

no -lm in sight.

The math library is used in Jorg's version, but it appears the eclipse version is not using the math library. Could make a big difference.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Outstanding, thank you! That wasted space is now reclaimed.

For anyone else that is looking to fix this issue with eclipse:

* Right-click on your project name and select Properties
* Expand C/C++ build and click on Settings
* Under AVR C Linker click on Libraries
* In the box under "Libraries (-l) click the Add... button and put the letter "m" in (nothing else needed).

Here is another helpful tip about the gnu99 standard:

Project --> Properties --> AVR Compiler --> Miscellaneous --> In the "other flags" box add "-std=gnu99"

Thanks again