I'm trying to convert a class header file from another c++ project to arduino, which in my mind involves replacing cout with Serial.println.
When I try to recomplile with all of these changes, I get this error from the compiler:
error: 'Serial' was not declared in this scope
Serial.print(p[i]);
Can someone explain this to me?
1 Answer 1
You have to #include <Arduino.h>
, or compile with the -include Arduino.h
flag. The Arduino IDE normally does that for you, but you have to do it yourself if you are working outside the IDE.
There are a couple of Arduino Makefiles floating around the Web which, just like the IDE, take care of this for you.
-
I'm actually using the Arduino IDE. :\Preston Shumway– Preston Shumway2015年05月16日 01:59:08 +00:00Commented May 16, 2015 at 1:59
-
Are you compiling a .ino or a .cpp? If it's a .cpp, the IDE is probably not adding the #include. If it's a .ino, it may just have messed your code. In the IDE options, you can ask to see all the compile-time messages. This will show the g++ command-line and tell you if it's compiling your original source or a modified version. You will also see the paths of the temporary cpp files it's creating, check their contents, and see if it has broken something.Edgar Bonet– Edgar Bonet2015年05月16日 08:18:35 +00:00Commented May 16, 2015 at 8:18