# Compilation Error

**URL:** <https://forum.sunfounder.com/t/compilation-error/3342>\
**Category:** Robotic kit for Arduino\
**Created:** [June 11, 2025, 9:07pm UTC](https://forum.sunfounder.com/t/compilation-error/3342 "2025-06-11T21:07:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Twinkle](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@Twinkle](https://forum.sunfounder.com/u/Twinkle)\
**Post date:** [June 11, 2025, 9:07pm UTC](https://forum.sunfounder.com/t/compilation-error/3342/1 "2025-06-11T21:07:44Z")

</div>

I have had the Galaxy Mars Robot running some time ago but when I tried to compile the sketch I get the error statement.  
/Users/anthonypiner/Documents/Arduino/libraries/libraries/SoftPWM/SoftPWM.cpp:41:10: fatal error: avr/io.h: No such file or directory  
#include \<avr/io.h\>  
^ ~~~~~~~~~  
compilation terminated.  
exit status 1

Compilation error: exit status 1  
SoftPWM has been included in the libraries. This is running on an iMac with Arduino 2.3.6.

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [June 12, 2025, 3:30am UTC](https://forum.sunfounder.com/t/compilation-error/3342/2 "2025-06-12T03:30:47Z")

</div>

Could you please specify:

1. Which sample code are you running?
2. Your detailed operation steps?

The error suggests required libraries may be missing. Please:

1. Reinstall these libraries:

- SoftPWM
- SunFounder AI Camera  
(Guide: [Library Installation](https://docs.sunfounder.com/projects/galaxy-rvr/en/latest/faq.html#compilation-error-softpwm-h-or-sunfounder-ai-camera-h-no-such-file-or-directory))

1. For best results:

- Download the complete code package ([Source Code ZIP](https://github.com/sunfounder/galaxy-rvr/archive/refs/heads/main.zip))
- Open/upload files from the downloaded folder (don’t copy-paste from tutorial)

Please try these steps and share your results.

---

<div class="post-metadata">

**Author:** ![Twinkle](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@Twinkle](https://forum.sunfounder.com/u/Twinkle)\
**Post date:** [June 12, 2025, 10:54am UTC](https://forum.sunfounder.com/t/compilation-error/3342/3 "2025-06-12T10:54:44Z")

</div>

Hi

Thanks for your response.

I have downloaded the complete package again and re-installed the two libraries required with the same result. (See screen shot). I assumed that it was a missing something from a library but have not found any reference to an avr/io.h: call or file.

 ![Screenshot 2025-06-12 at 11.44.56.png](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/9/95ec6aa60f5c6de045eccd739a2d5f0f6f3f5fb8.jpeg)

Many thanks

Kind regards

Tony Piner  
Apartment 7 The Point  
Pierhead  
Exmouth  
EX8 1FE  
01395 265025  
07860 705022  
///balloons.hometown.sparkles

---

<div class="post-metadata">

**Author:** ![Twinkle](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@Twinkle](https://forum.sunfounder.com/u/Twinkle)\
**Post date:** [June 12, 2025, 12:59pm UTC](https://forum.sunfounder.com/t/compilation-error/3342/4 "2025-06-12T12:59:51Z")

</div>

Hi

Gemini gave me a clue as to what the problem was. See below

This error message, “fatal error: avr/io.h: No such file or directory #include \<avr/io.h\>”, indicates that the compiler cannot find the header file `avr/io.h`. This almost always means you’re trying to compile code written for an AVR microcontroller (like those found in Arduino boards) in an environment that isn’t set up for AVR development.

Here’s a breakdown of why you’re getting this error and how to fix it:

**Why you’re getting this error:**

1. **Missing AVR Toolchain:** The `avr/io.h` file is part of the **AVR-GCC toolchain**. This toolchain includes the compiler (GCC), avr-libc (which provides standard libraries and header files like `avr/io.h`), and other utilities specifically designed for compiling code for AVR microcontrollers. If you don’t have this toolchain installed, or if your development environment isn’t configured to use it, the compiler won’t know where to find `avr/io.h`.

2. **Incorrect Compiler/IDE Setup:**

3. **Not targeting an AVR device:** This code is specifically for AVR microcontrollers. If you’re trying to compile it for a different architecture (e.g., ARM, x86), then `avr/io.h` is irrelevant and won’t be found.

**How to fix it:**

The solution depends on what you’re trying to do:

**1. If you’re developing for an AVR Microcontroller (e.g., Arduino):**

- **Install the AVR Toolchain:**

- **Configure your IDE/Build System:**

**2. If you’re NOT developing for an AVR Microcontroller (and just found this code):**

- **Recognize that the code is AVR-specific:** The `#include <avr/io.h>` line is a strong indicator that the code you’re trying to compile is designed for AVR microcontrollers.
- **Don’t try to compile it with a standard C/C++ compiler:** It won’t work without significant modification or porting.
- **Find an alternative:** If you’re trying to achieve a similar functionality on a different platform (e.g., a Raspberry Pi, a PC), you’ll need to find or write code that uses the I/O mechanisms of that specific platform.

**In summary, the core issue is that your development environment is not set up to compile code for AVR microcontrollers.** You need the AVR-GCC toolchain and your build system (IDE or Makefile) needs to be configured to use it and find its associated header files.

Essentially Arduino was still trying to compile for a previous board why I had been using (Arduino UNO R4) rather than an Arduino Uno AVR wifi board.

Once I had changed this the sketch now compiles.

Many thanks for your help.

Kind regards

Tony Piner  
Apartment 7 The Point  
Pierhead  
Exmouth  
EX8 1FE  
01395 265025  
07860 705022  
///balloons.hometown.sparkles

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [June 13, 2025, 5:47am UTC](https://forum.sunfounder.com/t/compilation-error/3342/5 "2025-06-13T05:47:36Z")

</div>

Yes. Before uploading the code, you need to select the correct development board and the correct port number.

Our Mars rover is configured with an UNO R3 board, so please ensure you select the correct board and port. Refer to the screenshot.

 ![image (55)](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/c/cf344f401864752429c9532db3f1e1aa01d17ed8.png)  
 ![image (54)](https://canada1.discourse-cdn.com/flex029/uploads/sunfounder/original/2X/6/6b1db1db7f2e5b0fe47bc6b8ecaec151c15b7c1f.png)
