0

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!

7
  • 3
    Have you installed avr-libc?
    – Majenko
    Commented 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
    Commented Feb 17, 2018 at 0:21
  • @NickGammon there are lots of reasons to avoid the IDE. christopherjmcclellan.wordpress.com/2018/02/16/…
    – RubberDuck
    Commented 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
    Commented 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. Commented Feb 17, 2018 at 15:42

1 Answer 1

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 and acknowledge you have read our privacy policy.

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