I am trying to use the atmega328p as standalone microchip and program it. I ama using an Arduino Uno as ISP. I have written a simple program to test it however when I try to compile it using
avr-gcc -mmcu=atmega328p -o main.out main.c
I get the error:
main.c:1:20: fatal error: avr/io.h: No such file or directory
compilation terminated.
I am running OpenSUSE Leap 42.3 and i have installed avr-gcc, avr-libc.
My code:
#include <avr/io.h>
int main() {
DDRB = 1;
PORTB = 1;
}
Thank you in advance!
-
3Have you installed avr-libc?Majenko– Majenko2018年02月16日 19:42:09 +00:00Commented Feb 16, 2018 at 19:42
-
You can use the Arduino IDE to compile such programs. What is the objection to doing that?Nick Gammon– Nick Gammon ♦2018年02月17日 00:21:42 +00:00Commented Feb 17, 2018 at 0:21
-
@NickGammon there are lots of reasons to avoid the IDE. christopherjmcclellan.wordpress.com/2018/02/16/…RubberDuck– RubberDuck2018年02月17日 11:32:06 +00:00Commented Feb 17, 2018 at 11:32
-
OK., Arduino IDE is subpar, but the main goal, e.g. producing Arduino executables is flawless. Did you tried UECIDE (uecide.org)? Eclipse plugin? Netbeans plugins?user31481– user314812018年02月17日 11:50:15 +00:00Commented Feb 17, 2018 at 11:50
-
[Opinion piece] If you want a (IMHO, a million times) better dev environment than Arduino IDE then start using PlatformIO. Automatically generates project files for every possible IDE out there, downloads the compilers and frameworks you need, 'just works' without worries.Maximilian Gerhardt– Maximilian Gerhardt2018年02月17日 15:42:58 +00:00Commented Feb 17, 2018 at 15:42
1 Answer 1
I’m guessing you started with the toolchain Arduino put on your machine.
Try explicitly including the header files on the include path with the -I
switch.
avr-gcc -mmcu=atmega328p -I /path/to/avr/include -o main.out main.c
Just search for the io.h
file. It should be somewhere close by to where you found the compiler.