Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Arduino and avr-g++ cannot find libraries
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
fabalthazar
n00b
n00b


Joined: 26 May 2015
Posts: 28
Location: France

PostPosted: Sat Sep 26, 2020 7:33 pm    Post subject: Arduino and avr-g++ cannot find libraries Reply with quote

Hello,

I am getting started with Arduino Uno and try to include built-in libraries and/or custom libraries. Compiling from Arduino IDE fails with avr-g++ not finding libraries:
Code:
fatal error: <EEPROM.h>: No such file or directory

The source code is:
Code:
#include <EEPROM.h>
#include <Servo.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}


I compiled an AVR toolchain with
Code:
crossdev -S -s4 --target avr
with success (gcc version 9.3.0).
I installed arduino 1.8.13 and arduino-builder 1.5.4 from portage repositories with success too.

I selected in Arduino IDE the right board (Arduino Uno).
I installed the Servo library (located in ~/Arduino/libraries/Servo/)
Arduino IDE detects it correclty as Servo appears in "File -> Examples" and in "Sketch -> Include Library"
It fails as with the EEPROM library.

EEPROM.h (builtin) and Servo.h (Custom) are located here:
Code:
/usr/share/arduino/hardware/arduino/avr/libraries/EEPROM/src/EEPROM.h
~/Arduino/libraries/Servo/src/Servo.h

I noticed that just before the fatal error "<EEPROM.h> : No such file or directory", appears this error:
Code:
Detecting libraries used...
/usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/usr/share/arduino/hardware/arduino/avr/cores/arduino -I/usr/share/arduino/hardware/arduino/avr/variants/standard /tmp/arduino_build_343258/sketch/sketch_sep26b_EEPROM.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Error while detecting libraries included by /tmp/arduino_build_343258/sketch/sketch_sep26b_EEPROM.ino.cpp

So I suppose either arduino-builder or avr-g++ fails to discover libraries (avr-g++ is called with -DARDUINO_LIB_DISCOVERY_PHASE).

Please note that I didn't install avr-gcc with --without-headers as one can find it in differents wikis. Could this have an effect on this problem?

Thanks for your help.
Back to top
View user's profile Send private message
Cervisator
n00b
n00b


Joined: 01 Oct 2020
Posts: 2

PostPosted: Thu Oct 01, 2020 6:31 pm    Post subject: Reply with quote

Exact same issue here on Arduino Nano, no solution yet... Tried to link the libraries to other locations - but no luck yet. And yes, it is strange that not even the pre-installed libraries (like EEPROM.h) can be found...

Help would be really appreciated! Thanks!
Back to top
View user's profile Send private message
fabalthazar
n00b
n00b


Joined: 26 May 2015
Posts: 28
Location: France

PostPosted: Thu Oct 01, 2020 7:00 pm    Post subject: Reply with quote

I found the root cause!

GCC is in charge of finding libraries (avr-g++) and Arduino IDE (or arduino-builder) looks not to be compatible with latest stable GCC 9.3.

I works with GCC 7.5.0.
To discover that, I downloaded the ready-to-use Arduino for Linux archive from the official Arduino website. They bundle avr-gcc 7.3. So I tried avr-gcc 7.5 available in Gentoo repositories.
Code:
sudo emerge --unmerge --ask cross-avr/avr-libc cross-avr/binutils cross-avr/gcc
sudo crossdev --clean avr
sudo crossdev -s4 --stable --gcc "<8.0.0" --portage --verbose --target avr

I could be interesting to test GCC 8 also.

To understand this incompatibility, one may have to dive into Arduino...

Tell me if this GCC downgrade works for you too. In such case it could be useful to change the wiki.
Back to top
View user's profile Send private message
x90e
n00b
n00b


Joined: 30 Sep 2020
Posts: 40

PostPosted: Thu Oct 01, 2020 7:20 pm    Post subject: Re: Arduino and avr-g++ cannot find libraries Reply with quote

fabalthazar wrote:

Code:
/usr/share/arduino/hardware/arduino/avr/libraries/EEPROM/src/EEPROM.h
~/Arduino/libraries/Servo/src/Servo.h

I noticed that just before the fatal error "<EEPROM.h> : No such file or directory", appears this error:
Code:
Detecting libraries used...
/usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/usr/share/arduino/hardware/arduino/avr/cores/arduino -I/usr/share/arduino/hardware/arduino/avr/variants/standard /tmp/arduino_build_343258/sketch/sketch_sep26b_EEPROM.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Error while detecting libraries included by /tmp/arduino_build_343258/sketch/sketch_sep26b_EEPROM.ino.cpp



well what i'm seeing in that /usr/bin/avr-g++ line is that you are including (-I) 2 directories that are close to the one you want, /usr/share/arduino/hardware/arduino/avr/libraries/EEPROM/src/EEPROM.h ... /usr/share/arduino/hardware/arduino/avr/cores/arduino and /usr/share/arduino/hardware/arduino/avr/variants/standard so it looks like you just need to tell the Arduino? application to include that directory in the libraries that it looks for (/usr/share/arduino/hardware/arduino/avr/libraries - i'm assuming this is the one you want to add so that it will catch everything that falls under it) I remember having to configure library locations when I used arduino awhile ago but I don't remember the exact steps. You could just add it to that line with an -I/usr/share/arduino/hardware/arduino/avr/libraries but im assuming that you aren't running that code by hand and will need to include the library in the entire project.
Back to top
View user's profile Send private message
Cervisator
n00b
n00b


Joined: 01 Oct 2020
Posts: 2

PostPosted: Thu Oct 01, 2020 8:00 pm    Post subject: Reply with quote

fabalthazar wrote:
I found the root cause!

GCC is in charge of finding libraries (avr-g++) and Arduino IDE (or arduino-builder) looks not to be compatible with latest stable GCC 9.3.

I works with GCC 7.5.0.
To discover that, I downloaded the ready-to-use Arduino for Linux archive from the official Arduino website. They bundle avr-gcc 7.3. So I tried avr-gcc 7.5 available in Gentoo repositories.
Code:
sudo emerge --unmerge --ask cross-avr/avr-libc cross-avr/binutils cross-avr/gcc
sudo crossdev --clean avr
sudo crossdev -s4 --stable --gcc "<8.0.0" --portage --verbose --target avr

I could be interesting to test GCC 8 also.

To understand this incompatibility, one may have to dive into Arduino...

Tell me if this GCC downgrade works for you too. In such case it could be useful to change the wiki.


Dear fabalthazar,

I can confirm the solution: The gcc-downgrade does the trick. Now everything works as expected on my computer as well and I'm quite happy. I even had to use Windows during the last days to program my Arduino! :roll:

Thanks a lot and have a nice day!
Back to top
View user's profile Send private message
chl
n00b
n00b


Joined: 13 May 2003
Posts: 72
Location: Munich

PostPosted: Wed Nov 04, 2020 8:59 am    Post subject: Reply with quote

Had the same problem. The downgrade helped me too.

Quote:
I could be interesting to test GCC 8 also.


Can confirm that gcc-avr-8.4.0 worked for me.

Code:
crossdev -s4 --stable --gcc "<9.0.0" --portage --verbose --target avr


CHL
_________________
The difficulty in designing something completely foolproof, is not to underestimate the ingenuity of complete fools.
Back to top
View user's profile Send private message
surabujin
n00b
n00b


Joined: 04 Oct 2024
Posts: 1

PostPosted: Fri Oct 04, 2024 10:47 pm    Post subject: Reply with quote

The root cause is localized output from gcc. Looks like arduino-builder parsing error about missing includes and perform search for them using it's own logic. But if locale is not en.* it can't parse gcc output and do not perform search for missing includes.

So the solution is to set LC_ALL=C.UTF-8 to forge gcc to use en locale, or compile gcc with USE=-nls flag

Code:
USE=-nls crossdev -s4 --stable --portage --verbose --target avr


Code:
$ /usr/bin/avr-g++ --version
avr-g++ (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


I have found coresponding issue into arduino-builder https://github.com/arduino/arduino-builder/issues/243.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum