Im trying to use XCode to compile avr program with arduino libs but seems like something wrong with my Makefile because it throws me warnings like

# warning "F_CPU not defined for <util/delay.h>"

but I use -D on CC and CXX which should define stuff I thought, here is my Makefile:

TARGET              = firmware
MCU                 = atmega32u4
F_CPU               = 16000000L
USB_VID             = 0x2a03
USB_PID             = 0x8036
USB_PRODUCT         = "USB Device"
ARDUINO_VERSION     = 107010

CC   =
CXX  = avr-g++
AR   = avr-ar
COPY = avr-objcopy
SIZE = avr-size
DUDE = avrdude


all: compile


    $(shell $(CXX) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo src/program.cpp -o build/program.cpp.o)

    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/hooks.c -o build/hooks.c.o)
    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/WInterrupts.c -o build/WInterrupts.c.o)
    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/wiring.c -o build/wiring.c.o)
    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/wiring_analog.c -o build/wiring_analog.c.o)
    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/wiring_digital.c -o build/wiring_digital.c.o)
    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/wiring_pulse.c -o build/wiring_pulse.c.o)
    $(shell $(CC) $(CFLAGS) -I arduino -I arduino/variants/leonardo arduino/wiring_shift.c -o build/wiring_shift.c.o)

    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/abi.cpp -o build/abi.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/CDC.cpp -o build/CDC.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/HardwareSerial.cpp -o build/HardwareSerial.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/HardwareSerial0.cpp -o build/HardwareSerial0.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/HardwareSerial1.cpp -o build/HardwareSerial1.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/HardwareSerial2.cpp -o build/HardwareSerial2.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/HardwareSerial3.cpp -o build/HardwareSerial3.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/HID.cpp -o build/HID.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/IPAddress.cpp -o build/IPAddress.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/main.cpp -o build/main.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/new.cpp -o build/new.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/Print.cpp -o build/Print.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/Stream.cpp -o build/Stream.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/Tone.cpp -o build/Tone.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/USBCore.cpp -o build/USBCore.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/WMath.cpp -o build/WMath.cpp.o)
    $(shell $(CPP) $(CPPFLAGS) -I arduino -I arduino/variants/leonardo arduino/WString.cpp -o build/WString.cpp.o)

    $(shell $(AR) rcs build/core.a build/hooks.c.o)
    $(shell $(AR) rcs build/core.a build/WInterrupts.c.o)
    $(shell $(AR) rcs build/core.a build/wiring.c.o)
    $(shell $(AR) rcs build/core.a build/wiring_analog.c.o)
    $(shell $(AR) rcs build/core.a build/wiring_digital.c.o)
    $(shell $(AR) rcs build/core.a build/wiring_pulse.c.o)
    $(shell $(AR) rcs build/core.a build/wiring_shift.c.o)
    $(shell $(AR) rcs build/core.a build/abi.cpp.o)
    $(shell $(AR) rcs build/core.a build/CDC.cpp.o)
    $(shell $(AR) rcs build/core.a build/HardwareSerial.cpp.o)
    $(shell $(AR) rcs build/core.a build/HardwareSerial0.cpp.o)
    $(shell $(AR) rcs build/core.a build/HardwareSerial1.cpp.o)
    $(shell $(AR) rcs build/core.a build/HardwareSerial2.cpp.o)
    $(shell $(AR) rcs build/core.a build/HardwareSerial3.cpp.o)
    $(shell $(AR) rcs build/core.a build/HID.cpp.o)
    $(shell $(AR) rcs build/core.a build/IPAddress.cpp.o)
    $(shell $(AR) rcs build/core.a build/main.cpp.o)
    $(shell $(AR) rcs build/core.a build/new.cpp.o)
    $(shell $(AR) rcs build/core.a build/Print.cpp.o)
    $(shell $(AR) rcs build/core.a build/Stream.cpp.o)
    $(shell $(AR) rcs build/core.a build/Tone.cpp.o)
    $(shell $(AR) rcs build/core.a build/USBCore.cpp.o)
    $(shell $(AR) rcs build/core.a build/WMath.cpp.o)
    $(shell $(AR) rcs build/core.a build/WString.cpp.o)

    $(shell $(CC) -w -Os -Wl,--gc-sections -mmcu=$(MCU) -o build/program.cpp.elf build/program.cpp.o build/core.a -Lbuild -lm)

    $(shell $(COPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 build/program.cpp.elf build/program.cpp.eep)
    $(shell $(COPY) -O ihex -R .eeprom build/program.cpp.elf build/program.cpp.hex)

$(TARGET).bin: compile

    $(shell $(COPY) -O binary build/program.cpp.elf $(TARGET).bin)

  • Where did you read that you want to use $(shell ...) for all commands? Commented Oct 14, 2016 at 19:53
  • found in web, XCode show error " *** missing separator . Stop" if I not using shell
    – user840250
    Commented Oct 14, 2016 at 19:59
  • @user840250 Do you have a tabs as indents? Four spaces won't work in Makefile.
    – KIIV
    Commented Oct 14, 2016 at 20:11
  • You're confusing CPP (the C PreProcessor, avr-cpp when called from avr-gcc or avr-g++) with CXX (avr-g++) with disastrous results.
    – Majenko
    Commented Oct 14, 2016 at 21:37

1 Answer 1


You are using $(CPPFLAGS) for *.cpp files but only $(CXXFLAGS) are defined.

This should be obvious from command line (if you enable showing executed commands for make)

And also:

  • CC =
  • using $(CPP) again only $(CXX) is defined

And don't forget Makefile needs tabs for indenting target commands (here you have four spaces, but it might be just replaced by SE)

  • oh... seems like I need some sleep :) thanks.
    – user840250
    Commented Oct 14, 2016 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.