Go Down

Topic: Library Problem With IDE V1.5.1r2 And Due (Read 22076 times) previous topic - next topic


I have a rather complex sketch running on a Mega 2560. It works fine on both V1.5.1r2 and V1.0.3. On the former IDE, it compiles when selecting the Mega 2560 board but fails when selecting the Due programming port. The error statement is as follows.

C:\Users\xxxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory
compilation terminated.

I can find the missing io.h header file but it's not anywhere near the searched area. It's found at the following location.


So the question is: how do I get it to look in the right location? Since I'm using the 2.8" TFT, I expect other errors to come up later. However, I have to fix them as they show up.



I generally copy the Arduino 'tree' for each new version to a subfolder of a Program Files folder, so I now have several copies of that file.  The bottom two in the listing below show both 1.0.3 and 1.5.1r2 as having the file in the same relative location, i.e.


   Does this help?

Directory of F:\Program Files\Arduino\Arduino ERW 1.0.3\hardware\tools\avr\avr\include\avr

09/01/2010  21:03            14,436 io.h
               1 File(s)         14,436 bytes

Directory of F:\Program Files\Arduino\arduino-0018\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-0022\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-0023\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-1.0\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-1.0.1\hardware\tools\avr\avr\include\avr

04/12/2008  20:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-1.0.2\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-1.0.3\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes

Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\tools\avr\avr\include\avr

04/12/2008  21:36            11,481 io.h
               1 File(s)         11,481 bytes


That's where the file is located but the IDE doesn't seem to look in that location. I've added a full path #include statement to the sketch and it solved that particular error. However, now it complains that sfr_defs.h is missing. I added a full path #include to that file, which happens to be in the same folder, but it still complains. I'm at a lose now as a full description of it's location doesn't work. The puzzling thing is that when compiling for the Mega 2560 it all works even without the extra #includes. I guess IDE V1.5.1r2 beta is just buggy. Without it running correctly, my Due project goes back to the shelf and I'll continue with the Mega.

My installation never put the program in the Program Files folder. It left it in Downloads/Arduino where I put the original ZIP file.


What's the location of the Arduino.exe you're running to get 1.5?

From what you've said, I reckon it should be:


If that's where the exe is, maybe check your desktop shortcut (f that's what you're using) - the target and start folder should be:

Target:    "C:\Users\xxxxx\Downloads\Arduino\arduino-1.5.1r2-windows\arduino-1.5.1r2\arduino.exe"
Start in:     "C:\Users\xxxxx\Downloads\Arduino\arduino-1.5.1r2-windows\arduino-1.5.1r2"

Personally I would make a copy somewhere else, e.g. under Program Files, so that you can do whatever you like in your Downloads folders, e.g. delete them all if necessary sometime.



The start folder and EXE pointer are as you stated. This has been the case for all versions of the IDE from 022 thru 1.5.1r2. They have all been in the "C:\Users\xxxxx\Downloads\Arduino\" folder but within another sub-folder of their own name.

The really puzzling part is that the same sketch compiled in V1.5.1r2 works when selecting the Mega 2560 board and fails with the Due board. That makes me think it's a bug in the new IDE.


I know your sketch is complex, but could you possibly pare it down to a minimum (that fails) and post it here please?

I'll have a look.



There is no apparent point in the sketch that fails as the compiler hasn't gotten that far yet. It fails in what appears to be the first stage of #include library searches. There is only one error line printed and is shown below.

C:\Users\xxxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory
compilation terminated.

Apparently, the IDE is not looking in the right location for header files as they all exist. I can fix the io.h error by including the full path to the file. However, it then complains that sfr_defs.h is missing. A full path #include statement does not fix this problem so I have no way of continuing.

Here are some lines of compiler output that precedes the error line. As I said, it's the Due that dies. I'm going to try commenting out various #include statements to see if one of them is the culprit. It's known that Adafruit_TFTLCD is not compatible with the Due.

C:\Users\Root2\Documents\Arduino\libraries\Wire\utility\twi.c -o


I commented out a few #include statements. The compiler responds appropriately with errors. This tells me that there's nothing wrong in the sketch in terms of code. The problem then appears to be in the object code building stage. Various code files are not found where expected.

I can compile and run other simple example Due sketches without error.

I remember an earlier problem with the IDE whereby some folder names were case sensitive. I wonder if this problem might still exist in some file names.


Hi Eddie,

Re-reading your posts, I think the problem is just down to the difference in architecture between the Due (ARM based - "Atmel SAM3X8E ARM Cortex-M3") and the earlier Arduino boards (AVR based, e.g. ATmega2560).  When you compile for the Due it's using the files under hardware\arduino\sam, and there's simply no header file called io.h.

I've listed all the available header files under hardware\arduino\sam below.

The Due requires various libraries to be re-written or 'ported' to it, and it would be fantastic if someone with more knowledge than me could list what's available and what isn't (yet) - any volunteers please?


Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\cores\arduino

06/11/2012  12:02             4,756 Arduino.h
06/11/2012  12:02            10,379 binary.h
06/11/2012  12:02               697 Client.h
06/11/2012  12:02             1,325 HardwareSerial.h
06/11/2012  12:02             2,978 IPAddress.h
06/11/2012  12:02             1,264 itoa.h
06/11/2012  12:02             2,505 Print.h
06/11/2012  12:02             1,335 Printable.h
06/11/2012  12:02               956 Reset.h
06/11/2012  12:02             1,353 RingBuffer.h
06/11/2012  12:02               111 Server.h
06/11/2012  12:02             4,005 Stream.h
06/11/2012  12:02             1,731 syscalls.h
06/11/2012  12:02               854 Tone.h
06/11/2012  12:02             1,785 UARTClass.h
06/11/2012  12:02             4,180 Udp.h
06/11/2012  12:02             1,795 USARTClass.h
06/11/2012  12:02             4,769 WCharacter.h
06/11/2012  12:02             1,080 WInterrupts.h
06/11/2012  12:02             2,310 wiring.h
06/11/2012  12:02             2,094 wiring_analog.h
06/11/2012  12:02             2,614 wiring_constants.h
06/11/2012  12:02             2,729 wiring_digital.h
06/11/2012  12:02             1,083 wiring_private.h
06/11/2012  12:02             1,307 wiring_pulse.h
06/11/2012  12:02             1,157 wiring_shift.h
06/11/2012  12:02             1,147 WMath.h
06/11/2012  12:02             8,489 WString.h
              28 File(s)         70,788 bytes


Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\cores\arduino\USB
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\firmwares\atmega16u2\arduino-usbserial
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\firmwares\atmega16u2\arduino-usbserial\Board
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\firmwares\atmega16u2\arduino-usbserial\Lib
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\Audio
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\Ethernet
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\Ethernet\utility
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\Scheduler
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\SPI
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\USBHost
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\libraries\Wire


Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\system
Directory of F:\Program Files\Arduino\arduino-1.5.1r2\hardware\arduino\sam\variants


Yes, the IDE V1.5.1r2 is not ready for primetime with the Due. I'll just keep watching this forum for news and clues.

Your library listing is interesting in that my first attempt at compiling failed due to itoa.h being missing. However, it's in the list at

06/11/2012  12:02             1,264 itoa.h

I ended up using sprintf() to prepare a string for display on the 2.8" TFT from Adafruit. It turned out to be a better choice in that I can combine some text and integer data in the same statement.



From what I see here, io.h seems to be part of AVR toolchain and related to AVR devices peripheral registers.

So, don't expect this to be exactly the same for an ARM based device, read: not part of a generic ARM GCC distribution.

But, similar information is provided here: arduino-1.5.1r2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa

Going back to the issue:
C:\Users\xxxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory
compilation terminated.

This shows that the IDE is trying to compile the AVR dedicated library instead of the SAM one.
The main difference is that all peripheral drivers for the Due/SAM3X are contained into libsam (arduino-1.5.1r2\hardware\arduino\sam\system\libsam) so that they are available to any additional library/applicaiotn and thus don't need to be added into any local folder.

This should not happen regarding the fact you selected the Arduino Due board in the menu, I guess.


My feeling also in that selecting the Due board should aim the library search to the correct files. Since the IDE is an early release, r2, there are still bugs that have to be addressed. Until this task is complete, Due sketch development will be very frustrating. I've tried all my complex sketches in Due mode and none will compile. The error messages relate to library problems that I have no clue as to how to solve. As I said earlier, my Due is going back on the shelf until the situation improves.


Here's a thought. My first error involved a call from twi.c to avr/io.h. Since the board is not an avr then the call in twi.c might be to  sam.pio.h. I'm just guessing on that one. Here's a possible solution. Wherever a call to avr.io.h exists, the following directive can be entered. This would have to be entered into the offending file so that it knew which board was being used. Searching for board types found that __SAM3X8E__ is the name of the Due board. Does this idea have possibilities since the IDE encounters calls to some avr libraries.

#if defined(__SAM3X8E__)
    #include <sam/pio.h> // For the Due
    #include <avr/io.h>    // For anything else before the Due


I am having the exact same issue.  It's clear the Arduino software is not ready for the Due, if you following my comments, you'll see the troubleshooting shows the same code will work with the Mega selected but not with the Due:


I hope someone can fix this as it heavily impacts my work withe Due.


My scheme shown above did not work entirely. It did prove that the Due board is named "__SAM3X8E__" as it looked for sam/pio.h. However, it did not find that file either so the solution will not work.

Go Up