Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preprocessor fails on #include "ESP8266wifi.h" (for external ESP8266 addon) #68

Closed
ladyada opened this issue Nov 21, 2015 · 39 comments · Fixed by arduino/ctags#4
Closed
Assignees
Labels
help wanted Assistance from the community is especially welcome topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project

Comments

@ladyada
Copy link

ladyada commented Nov 21, 2015

there's something about this header file that crashes the preprocessor, probably indicates some more general purpose bug. reproduce by:

  • add http://arduino.esp8266.com/stable/package_esp8266com_index.json to board manager prefs
  • use board manager to install ESP8266 support
  • try to compile this sketch
#include "ESP8266WiFi.h"
void setup() {}
void loop() { hello(); }
void hello(void) {}
  • will fail due to not having auto-generated prototype for hello()
  • now put #include "ESP8266WiFi.h" on last line, recompile
  • works now because while it does crash on the #include, its after the prototypes are made (?)

Also mentioned @ esp8266/Arduino#1066

@igrr
Copy link

igrr commented Nov 21, 2015

The #include which triggers the issue is #include <memory> in WiFiClient.h.
I have created a library with a single .h file (Dummy.h):

#include <memory>

Including this library in the sketch seems to be enough to trigger the issue.

Edit: actually we don't even need a library to trigger this. Compiling this sketch leads to the same error:

#include <memory>
void setup() {
  test();
}
void loop() {}
void test() {}

Edit 2: here's the output of arduino-builder with --debug=10: http://hastebin.com/matajofoti.md

Edit 3: interestingly, the list of prototypes is generated correctly by ctags:

$ "/Users/igrokhotkov/projects/esp8266/arduino.cc/master/build/macosx/work/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino4/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns "/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/buildad5feee0973bd3788deb217687c83661.tmp/preproc/ctags_target.cpp"
setup   /var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/buildad5feee0973bd3788deb217687c83661.tmp/preproc/ctags_target.cpp /^void setup() {$/;"    kind:function   line:4  signature:()    returntype:void
loop    /var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/buildad5feee0973bd3788deb217687c83661.tmp/preproc/ctags_target.cpp /^void loop() {$/;" kind:function   line:9  signature:()    returntype:void
test    /var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/buildad5feee0973bd3788deb217687c83661.tmp/preproc/ctags_target.cpp /^void test() {}$/;"    kind:function   line:14 signature:()    returntype:void

But the .ino.cpp file generated in the next step doesn't contain void test() prototype:

#include <Arduino.h>
#line 1
#line 1 "/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/arduino_ad5feee0973bd3788deb217687c83661/sketch_nov21a.ino"
#include <memory>
void setup() {
  test();
}
void loop() {}
void test() {}

@igrr
Copy link

igrr commented Nov 21, 2015

I pulled the latest git version of Arduino and rebuilt it. Also renamed test to myfunc to make it easier to grep.

Here's arduino-builder output: http://hastebin.com/mupuhalehe.cs
ctags_target_for_gcc_minus_e.cpp: https://gist.github.com/igrr/3095758a66bc28f7db23 (too large for hastebin:)
ctags output: https://gist.github.com/igrr/805dc5ef96cf9c0a0892
Note that there's really no myfunc in ctags output.

I had a thought that ctags gets confused by some of the c++11 constructs. Tried universal-ctags, and output looks much better (i.e. noexcept is no longer tagged as a function), but still it doesn't have myfunc.

@tigoe
Copy link
Member

tigoe commented Nov 22, 2015

Haven't got a solution but I can reproduce all of the errors down to the rebuild reliably, and it definitely seems to be what caused #4137.

@ffissore ffissore self-assigned this Nov 23, 2015
@ffissore
Copy link
Contributor

At a first look, it looks like ctags is interrupting. It's not getting beyond that tuple_element. I'm investigating why

@igrr
Copy link

igrr commented Nov 23, 2015

For the record, here's what i get from universal-ctags: https://gist.github.com/igrr/b82b708af81e7baa02fc
Unlike ctags shipped with Arduino, it is able to parse newer C++ keywords like noexcept. Still doesn't return full output though.

@ffissore
Copy link
Contributor

Indeed, even universal-ctags misses myfunc. Rebasing our ctags fork on top of universal-ctags is a nice-to-have (and tracked at arduino/ctags#2) but currently not in my todo list

@ffissore
Copy link
Contributor

I'm now using this

#include "ESP8266WiFi.h"
void setup() {
}
void loop() {
  myfunc();
}
void myfunc() {
}

When running ctags with -V (verbose) at the top of its output it prints
/tmp/arduino_12f75e84123cf24fa7ce3d06ac6342b3/sketch_nov23a.ino: failed to find match for '(' at line 36991
36991 is the last line of ctags_target_for_gcc_minus_e.cpp. A similar error message is displayed even after manually adding the prototype at the top of the sketch or removing all functions and leaving the sketch with just the first #include.

@ffissore
Copy link
Contributor

Same does universal-ctags

@matthijskooijman
Copy link
Collaborator

#88 also ran into a problem with ESP8266wifi.h. I dug into that, without being aware of this issue and found that static_assert was the culprit. I wrote:

I've found the cause of the problem: The static_assert keyword, which is
used by the ESP / libstdc++ include files, is confusing ctags and
prevents it from emitting information about subsequent functions. I've
filed a report here: https://sourceforge.net/p/ctags/bugs/370/ (though
exuberant ctags doesn't seem to be really maintained anymore, so this
report serves more as documentation than that I really expect it to be
fixed).

The proper fix would be to add support for static_assert in the Arduino
ctags version, but I'm afraid that might not be so easy. I won't have
time for looking at that on the short term.

Looking through the comments here, I'm not sure if this is exactly the same issue, though that might be caused by changes in the ESP core since this issue was created. I haven't tried universal-ctags to see what that gives.

@igrr
Copy link

igrr commented Jan 20, 2016

Oh wow, thanks for info Matthijs. I was going through the logs multiple times but missed this static_assert somehow.
I am pretty sure the issue was not related to the ESP core itself. It was easy to reproduce by including <memory> in the sketch, which is a libstdc++ header.
I'll give a shot at writing a patch for ctags (should be a matter of adding this missing keyword).

@matthijskooijman
Copy link
Collaborator

@igrr, yeah I think in my testing, the offending static_assert was in <array>. Having a patch would be great, thanks for looking at that!

@igrr
Copy link

igrr commented Jan 20, 2016

@matthijskooijman here you go: arduino/ctags#4

@matthijskooijman
Copy link
Collaborator

@igrr, awesome!

I just tested that PR with the example from my sourceforge bug report and the sketch from #88, which both work now. @cmaglie, can you take care of building binaries for ctags and doing an arduino-builder release?

@mkeyno
Copy link

mkeyno commented Feb 4, 2016

@igrr
I downloaded the hourly version but not fixed , I've got same compiler error, I don't know what should I suppose to do?

captive advance portal example


exit status 1
'handleRoot' was not declared in this scope

@stefangordon
Copy link

If the problem is related to this issue you can work around it by providing your own function prototypes as you would typically do in a C application. You just need to define the functions at the top of your .ino for example, or potentially in a separate header file.

@igrr
Copy link

igrr commented Feb 4, 2016

@matthijskooijman Looks like we have another issue due to use of enum class feature in DNSServer library: https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/src/DNSServer.h#L9
ctags is not aware of this new C++11 construct, which breaks parsing. I'll attempt a pull request to arduino-ctags.

@igrr
Copy link

igrr commented Feb 4, 2016

I have cherry-picked two more changes from geany. This fixes an issue with DNSServer library:
arduino/ctags#5
@cmaglie Could you please update ctags again? Thanks.

@julianh2o
Copy link

How does one generate the useful debugging output for this bug? This issue is closed, but it seems like including the FastLED library is still causing issues:

#include "FastLED.h"
void setup() { myctagstestfunc(); }
void myctagstestfunc() { }
void loop() {}

Fails with: error: 'myctagstestfunc' was not declared in this scope

On the 1.6.8 hourly build 2016/02/22 10:12 (downloaded just now)

According to FastLED/FastLED#258, this is still an arduino-builder issue, is that the case?

Should this be reopened?

@focalintent
Copy link
Contributor

@julianh2o I just opened up #120 for the specific issue you're seeing there (since I think this is being caused by slightly different things that were causing the problems here).

@focalintent
Copy link
Contributor

Pull request for a fix to #120 opened here - arduino/ctags#7

@vmanan
Copy link

vmanan commented Mar 6, 2016

Folks,

I tried hourly build 2016/03/04 and still seeing the error. Isnt the original error "memory" fixed?

In file included from C:\Users\vmanan\Documents\Arduino\libraries\src/ESP8266WiFi.h:32:0,
from myrobot.ino:3:
C:\Users\vmanan\Documents\Arduino\libraries\src/WiFiClient.h:28:18: fatal error: memory: No such file or directory
#include

@joeuser846
Copy link

This still happens with 1.6.8. What was/is the resolution?

@facchinm
Copy link
Member

facchinm commented Apr 6, 2016

@joeuser846 , it is fixed in 1.6.8+ (just tested with the initial sketch and ESP core 2.1.0)
Can you post the complete error?

@netmindz
Copy link

I'm still seeing issues with 1.6.8

@igrr
Copy link

igrr commented Apr 15, 2016

@netmindz Possibly you are seeing #1898, caused by arduino/ctags#10.
Try removing ESP8266WiFiMulti if you are using it.

Ketturi added a commit to Ketturi/LedMatrix that referenced this issue Apr 18, 2016
Had to flip whole structure upside down because this piece of ****:
arduino/arduino-builder#68
arduino/arduino-builder#80
arduino/arduino-builder#85 and countless other
issue tickets, arduino builder preprocessor fails to do prototype and
can't reorder functions so everything must be just in the right order
(and also breaks many libraries and other third party boards). Code may
not compile properly as long as arduino developpers can't get their ****
together. Wifi part won't work until underlying issue in arduino-builder
gets fixed or old version of arduino ide is used or something is gludged
to overcome these issues.
@stephanemorin
Copy link

I confirm I'm still seeing issues with 1.6.8 and ESP8266Wifi.
No improvement with the latest hourly build.
Not able to use the ESP8266wifi library anymore.

@igrr
Copy link

igrr commented Apr 18, 2016

@stephanemorin please provide the sketch which causes issues. Thanks.

@stephanemorin
Copy link

stephanemorin commented Apr 22, 2016

Hi igrr,

The following files from the ESPWifi library examples are all causing the same problem:
WifiClient.ino
WifiClientBasic.ino
WifiWebServer.ino

The error message is:

ESP8266WiFi\src/WiFiClient.h:24:18: fatal error: memory: No such file or directory
 #include <memory>
                  ^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.

cmaglie added a commit that referenced this issue May 6, 2016
Signed-off-by: Cristian Maglie <c.maglie@arduino.cc>
@19eighties
Copy link

I am seeing a similar issue with 1.6.9 and ESP8266WiFiMulti.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Assistance from the community is especially welcome topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.