[SOLVED} Multiple IDE tabs issue

I create a simple sketch with 3 tabs:
Sketch
#include <Arduino.h>

a_setup

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

b_loop

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

Compile fails with nearly 1000 lines of errors, the first two are :

sketch\sketch.ino.cpp:1:1: error: stray '##' in program
 ##line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\a_setup.ino"
 ^~
sketch\sketch.ino.cpp:1:3: error: 'line' does not name a type; did you mean 'sinf'?
 ##line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\a_setup.ino"
   ^~~~
   sinf

a_setup:0:1: error: 'line' does not name a type; did you mean 'sinf'?

In Windows temp folder: Arduino build xx / sketch/ sketch.ino.cpp:

##line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\a_setup.ino"
void setup();
#line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\b_loop.ino"
void loop();
#line 0 "C:\\Users\\Glenn\\Desktop\\sketch\\a_setup.ino"
line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\sketch.ino"
#include <Arduino.h>
#line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\a_setup.ino"
void setup() {
  // put your setup code here, to run once:
}
#line 1 "C:\\Users\\Glenn\\Desktop\\sketch\\b_loop.ino"
void loop() {
  // put your main code here, to run repeatedly:
}

It seems there is a fault in the compiler, it happens on both my PCs.

Please read the instructions for posting at the top of each forum and edit your post to correctly display the code. The forum editor doesn't keep the sketch formatting without code tags which makes it unreadable. If you post your code in code tags, more forum members will read it.

Post all of the code and the errors, also using code tags.

Here... your code with comments... compile this:

#include <Arduino.h>

/* a_setup should not be part of your sketch. I've commented it out here.

  a_setup

*/

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

/* b_loop should not be part of your sketch.   I've commented it out here.

  b_loop

*/

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

You misunderstand - I have three tabs named Sketch, a_setup and b_loop - named so that the compiler will add them in the correct order.
Sketch (same name as parent folder) contains includes and constructors, a_setup is the setup function, b_loop is the loop function.
It is a strategy that other people have used to break up their code into easily understood pieces. This is just a sample for testing, my real code has around 1300 lines.

I'm using IDE 1.8.5 with avr-gcc 7.3.0-atmel3.6.1-arduino7. Which versions do you use?

I get different errors when compiling your (3-file) sketch but your sketch compiles if I leave the #include out of the main sketch.

Please post this file: Arduino build xx / sketch/ sketch.ino.cpp

Do not do the #include <Arduino.h> in your main sketch (or in any .ino files.)
It's not necessary, and it seems to confuse things. (which is probably a subtle bug of some kind?)
I duplicated your setup, and it works fine with a completely empty sketch file.

Also, the order in which the files are "added" should be unimportant, so the a_ and b_ naming is unnecessary.

It appears that the IDE is inserting the function prototypes in the middle of another pre-processor line. It seems to be related to having a completely unnecessary "#include <Arduino.h>" in the main sketch. Removing Arduino.h in the Sketch avoids the problem. Replacing it with a different #include, like "Servo.h" avoids the problem.

Thanks everyone, the problem has disappeared. Other sketches didn't have Arduino.h and still failed, but all good now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.