need help using the avr-g++ compiler instead of using the IDE

The Arduino IDE automatically adds this line to your sketch:

#include <Arduino.h>

Did you add that line to your code?