title: How do I use clang to compile for avr (arduino)
body: <p>When I search I found 7yr old results talking about a fork of clang instead of clang itself.</p>
  <p>Using avr-gcc I can compile and upload my code with</p>
  <pre><code>avr-gcc a.cpp -DF_CPU=16000000 -mmcu=atmega2560 -Wall -Werror -Wextra -Os
  avr-objcopy -j .text -j .data -O ihex a.out my.hex
  sudo avrdude -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:my.hex:i
  </code></pre>
  <p>I'd like to replace the first step with <code>clang++</code>. The changes I made here</p>
  <ul>
  <li>avr-gcc to clang++</li>
  <li>Added <code>--target=avr</code></li>
  <li>Added <code>-nostdlib</code> because I'll include it myself</li>
  <li>Added <code>-I/usr/avr/include/</code> because path wasn't implicit</li>
  <li>Added <code>-L/usr/avr/lib/avr6 -lc -latmega2560</code> so it has enough info to build an elf</li>
  </ul>
  <p>I found device-specs at /usr/lib/gcc/avr/10.2.0/device-specs/specs-atmega2560 which mentions <code>crtatmega2560.o</code> and <code>-latmega2560</code> which appears to be located at <code>/usr/avr/lib/avr6/</code>. So I came up with the following and got these errors. How should I be compiling so I can get a hex to upload using avrdude?</p>
  <pre><code>$ clang++ a.cpp -DF_CPU=16000000 -mmcu=atmega2560 -Wall -Werror -Wextra -Os --target=avr -I/usr/avr/include/ -nostdlib -L/usr/avr/lib/avr6 -lc -latmega2560
  /usr/bin/avr-ld: skipping incompatible /usr/avr/lib/avr6/libc.a when searching for -lc
  /usr/bin/avr-ld: cannot find -lc
  /usr/bin/avr-ld: skipping incompatible /usr/avr/lib/avr6/libatmega2560.a when searching for -latmega2560
  /usr/bin/avr-ld: cannot find -latmega2560
  </code></pre>