1

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!

  • 2
    Have you installed avr-libc? – Majenko Feb 16 '18 at 19:42
  • You can use the Arduino IDE to compile such programs. What is the objection to doing that? – Nick Gammon Feb 17 '18 at 0:21
  • @NickGammon there are lots of reasons to avoid the IDE. christopherjmcclellan.wordpress.com/2018/02/16/… – RubberDuck Feb 17 '18 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 Feb 17 '18 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 Feb 17 '18 at 15:42
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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