IDE Can't find my TABs

I am working on a project that I have broken into several tabs, each with subset of the functions I have written, contained in an ino file. Everything was going fine. The IDE was combining the files, compiling, uploading to my dev board (an ESP32). Version 1 - fine. Made some changes: version 2 - fine. Made more changes: version 3 - and now the IDE cannot find any but the first (self-named) ino. The IDE reports that all of the functions that are defined in the second, third, fourth tabs (each with its own ino file) cannot be found.

Clearly I did something in the most recent edit that has caused this issue, but I cannot figure out what it is. I am hoping that someone might be able to point me in a good direction.

Thanks.

you need one directory that has the same name of your sketch's main .ino file and then the other .ino possibly in the directory

if you had the directory myproject holding myproject.ino and otherstuff.ino and if you renamed the directory into myprojectv3 then you need to change the name of the main ino into myprojectv3.ino (and keep otherstuff.ino next to it)

can you share more on your file structure?

Sure!

Inside my Arduino folder (I'm working on a Linux machine) I have a folder called cydTuner. Inside the cydTuner folder are four files: cydTuner.ino, ESPNow.ino, buttonStuff.ino, and relayStuff.ino. The cydTuner.ino file contains a bunch of #includes, a bunch of struct definitions, a void setup() function, and a void loop() function. The other files contain definitions of functions that are used in the cydTuner.ino file.

cydTuner compiles just fine.

Inside my Arduino folder is another folder, called cydTuner_v2. The cydTuner_v2 folder started life as a copy of the cydTuner folder, created by using the "Save As" button in the Arduino IDE. It also has 4 files (the same 4 as cydTuner, with one exception): cydTuner_v2.ino, ESPNow.ino, buttonStuff.ino, and relayStuff.ino. The last three files are unaltered copies of the files in the cydTuner folder. The cydTuner_v2.ino file has some alterations I have made, in pursuit of the ultimate goal of the application.

When I compile (Verify) cydTuner_v2, I get a bunch of errors of the form "error: 'blablaFunction' was not declared in this scope." All of the functions that are 'not declared in this scope' are functions that are defined in the three 'secondary' files: ESPNow.ino, buttonStuff.ino, and relayStuff.ino

I've tried to simulate this (on Windows 10) and the IDE refuses to create the v2 version.
image

So I did force it by using a Windows file explorer. Make a copy at the same level, rename directory and main ino and move it into the original.

After that I compiled the v2 compiled without problems.

To pinpoint where the real issue is, I suggest that you manually copy the original cydTuner.ino to the cydTuner_v2 directory and rename the copied cydTuner.ino to cydTuner_v2.ino and try to compile.


The use of multiple ino files does not always work reliably. Understanding that only the main ino file changed, that change between the original and the v2 version can have confused the Arduino builder.

The builder combines all ino files into one big file with the double extension ino.cpp. In case you're interested, you can find that ino.cpp file when you enable verbose output during compilation in file → preferences. When you compile, the output window will show you a line Linking everything together...; the line that follow tell you where the temporary version of your sketch is.

Linking everything together...
"C:\\Users\\Wim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega2560 -o "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C/1201361_v2.ino.elf" "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C\\sketch\\1201361_v2.ino.cpp.o" "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C/..\\..\\cores\\arduino_avr_mega_cpu_atmega2560_532122c45ee71fa3f92d689a8d73764d\\core.a" "-LC:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C" -lm
"C:\\Users\\Wim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C/1201361_v2.ino.elf" "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C/1201361_v2.ino.eep"
"C:\\Users\\Wim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C/1201361_v2.ino.elf" "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\4D1CC88D18DEF222A33F4B383E5AF81C/1201361_v2.ino.hex"

The first line shows the path (it will be different on your system) C:\Users\Wim\AppData\Local\Temp\arduino\sketches\4D1CC88D18DEF222A33F4B383E5AF81C. You can analyse that file to try to find out where the actual problem is.

I have two suggestions

  1. If you want somebody to have a look at the problem, post all four files of the v2 sketch here as well as the complete error message; you have been away for a bit from the forum so please don't forget the code tags for all of them :wink:
    It would also be useful to post the original cydTuner.ino so we can compare the changes.
  2. Reorganise your versioning; create a directory cydTuner and inside it create the v1, v2 and so on versions.

Something else you can try is manually stuffing all the content of all the files into just one big file, starting with the main .ino (the one with setup and loop) and then the other alphabetically and try to compile that big file.

So, I began by taking J-M-L's suggestion, lumping all the files into one. Adding the secondary files to the end of the primary - meaning the function definitions from the secondary files occur after the close of the loop() function, a situation which, as I understand it, is perfectly acceptable - I got the same errors...not surprising, I suppose, as that is, so far as I understand, just what happens when the IDE compiles a sketch with multiple tabs.

So I moved the secondary file function definitions to a location above the setup function, and the sketch compiled without the 'not declared in this scope' errors.

However...

Buried in amongst all the other errors was: "error: expected declaration before '}' token" occurring at the last line of the primary file of the sketch (the close of the loop function).

So, it turns out that, in the course of my last edit, I managed to include an extra closing brace in the middle of the loop function, which made the last closing brace in the primary file of the sketch superfluous, which threw an error, as a result of which the compiler then didn't compile the functions in the secondary files, and thus they were "not declared in this scope."

After locating, and removing the mis-placed closing brace (and correcting a few other minor errors), it all compiled without error.

My thanks to J-M-L and sterretje for your responses.

Note to sterretje: On my Linux machine, using IDE 2.2.1, selecting the 'Save As' option in the File menu creates a new folder in the Arduino folder (assuming, I suppose, that the folder for originating sketch is also in the Arduino folder) , initially named "blabla_copy_yyyymmddhhmmss", containing all the files from the originating sketch. The initial name may be changed to whatever, and the primary ino file is renamed (to match the folder name) to whatever is entered in the Name field of the file save window.

Great that you got it sorted. If your issue is solved, you can mark the the topic as "solved" by clicking the "solution" button under the most useful reply (I would give J-M-L the honours).

It might be a Windows thing, not sure.

FYI
An Arduino sketch is a directory with a name (in your case e.g. cydTuner) that contains at least an ino file that has the same name (cydTuner.ino).

From your experience it seems possible to have a sketch inside a sketch but I do not think that it's the intention. Hence my suggestion to use a different structure for the versioning.

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