Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Multiple File Sketches? (Read 10835 times)
RayLivingston
Full Member
***
Offline



Posts: 158
California
Multiple File Sketches?
Jun 15th, 2014 at 9:30pm
 
How do I create a sketch consisting of multiple files?  I keep reading that this can be done in the Arduino IDE by adding files with no extension, and, apparently, having all such files open in the IDE.  It will then concatenate all the files into one source file, add prototypes for all functions, then compile.  This approach (brain dead though it sounds to me...) appears to not work when using AtmelStudio and  VisualMicro.  Is this correct, or am I doing something wrong.  If it doesn't work, is there a way to create multi-file sketches, short of explicitly #including them all, and hand-crafting all the prototypes?

Regards,
Ray L.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Multiple File Sketches?
Reply #1 - Jun 15th, 2014 at 11:19pm
 
Hi Ray,

Hopefully you meant "adding files with '.ino' extension" and not "no extension" as you said above?

Yes we support multiple '.ino' files, in the same way as the Arduino Ide. See the documentation which shows one way to do it http://www.visualmicro.com/page/User-Guide.aspx?doc=Add-Source-Files.html

You can add additional .ino files in a variety of ways such as right click the project name in the solution explorer and click add new item (look for the visual micro icons).

We will in a future release have a specific item template for the "Add Item" dialog. However you can also add a .txt or .cpp or .h and rename them to .ino files.

tip: All these sources files are simple text files, it is only the extension that differs. Visual Micro automatically detects .ino files and handles them correctly. So you can add them however you like.
Back to top
« Last Edit: Jun 15th, 2014 at 11:31pm by Visual Micro »  
WWW  
IP Logged
 
RayLivingston
Full Member
***
Offline



Posts: 158
California
Re: Multiple File Sketches?
Reply #2 - Jun 15th, 2014 at 11:51pm
 
Tim,

Actually, several references I found online explicitly state the files must have NO extension, which seemed really odd to me as well.

But, that aside, I just can't get it to work, even if ALL files have .ino extensions.  In fact, I get a compile error on the very first forward reference, and on every global variable, unless I manually add a prototype to the top of the main sketch file, and define all global variables at the top of the main sketch file.  Sounds like this should NOT be happening, but it is....

Regards,
Ray L.
Back to top
 
 
IP Logged
 
RayLivingston
Full Member
***
Offline



Posts: 158
California
Re: Multiple File Sketches?
Reply #3 - Jun 15th, 2014 at 11:58pm
 
OK, so I just played with it some more.  Looks like the way to do it is to use the main sketch to define all global variables, then put all the code in other .ino files.

Is it just me, or is this a pretty goofy build system?

Regards,
Ray L.
Back to top
 
 
IP Logged
 
RayLivingston
Full Member
***
Offline



Posts: 158
California
Re: Multiple File Sketches?
Reply #4 - Jun 16th, 2014 at 12:23am
 
This is peculiar....  Depending on how I arrange things in the .ino files, I still get undefined symbols.  I moved one function from one .ino file to another, and how that function gets flagged as undefined in one of the other .ino file.  Either move it back to the main .ino, or manually add a prototype in the main .ino, and all is well.

I am confused...

Regards,
Ray L.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Multiple File Sketches?
Reply #5 - Jun 16th, 2014 at 1:47am
 
Hi Ray,

I think you will find that this is just how arduino works. Yes it goofy. The order is important and believe it or not the order of the files when combined is alphabetical with uppercase first.

I used to sort them in alpha order without distinguishing the case but that caused a problem in a few projects that had relied on a case sensitive ordering (shudder). So we just do whatever the arduino ide does.

You can also use cpp files but you have to include them manually and mark everything as external so it can be reference easily from elsewhere. You don;t have to use external but it can be a halfway house between good cpp and .ino

If you are using atmel studio then the Visual Micro branch of the New Project Wizard provides an empty sketch with Cpp example.

For existing projects, you can use the "New Cpp" Visual Micro menu items that have various automated workflows attached.

I can't believe there are articles published suggesting no file extension. Crazy Smiley
Back to top
« Last Edit: Jun 16th, 2014 at 1:50am by Visual Micro »  
WWW  
IP Logged
 
RayLivingston
Full Member
***
Offline



Posts: 158
California
Re: Multiple File Sketches?
Reply #6 - Jun 16th, 2014 at 2:08am
 
Tim,

OK, thanks.  Guess I'll just have to embrace the goofiness.  Alphabetical....  Incredible, but I actually suspected as much, since the last file I added started with 'U'....  At some point, I'll just switch to straighr CPP.  It's not like I'm using much of the Arduino stuff at this point anyway - Mostly just Serial.

Regards,
Ray L.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Multiple File Sketches?
Reply #7 - Jun 16th, 2014 at 2:19am
 
Forgot to say, the [sketch name].ino is the one file that breaks the alphabetical rules, it's always first
Back to top
 
WWW  
IP Logged
 
Heinz Kessler
Full Member
***
Offline



Posts: 217
Freiburg, Germany
Re: Multiple File Sketches?
Reply #8 - Jun 16th, 2014 at 7:47pm
 
@
RayLivingston,
Hi Ray,
my name is Heinz Kessler, I am the author of the Visual Micro documentation.

We would like to make a FAQ or enhance an existing documentation article with your case.
Therefore my question:
What elements (global variables, function declaration...) were dependent of the order of the files?

Did you find a solution that worked for you or did you have to play around with filenames?

Thank you,

Heinz Kessler
visualmicro.com

Back to top
 
 
IP Logged
 
RayLivingston
Full Member
***
Offline



Posts: 158
California
Re: Multiple File Sketches?
Reply #9 - Jun 17th, 2014 at 1:02am
 
Heinz Kessler wrote on Jun 16th, 2014 at 7:47pm:
@
RayLivingston,
Hi Ray,
my name is Heinz Kessler, I am the author of the Visual Micro documentation.

We would like to make a FAQ or enhance an existing documentation article with your case.
Therefore my question:
What elements (global variables, function declaration...) were dependent of the order of the files?

Did you find a solution that worked for you or did you have to play around with filenames?

Thank you,

Heinz Kessler
visualmicro.com



Heinz,

The annoying thing is, I never seem to be able to find patterns to the wierd behaviors I see with the Arduino tools.  I can make some inane change, and suddenly things are borked.  In the current case, I split one large sketch into perhaps a half dozen .ino files, and immediately got errors due to some, not all, variables being referenced before they were declared.  That prompted me to move the definitions of all variables into the primary .ino file, to ensure they were defined before any code.  I then had just one function that was generating a linker error, and I had to add a prototype for that one function to the top of the .ino file.  Why only that one function?  Damned if I know!  But that's been my experience all along with Arduino builds all along - making some silly change over here will break something way over there, with no rhyme or reason.

Oddly, after I got it all to compile, I was able to move most of the data declarations into the files containing most of the code that referencese them, and it still compiles fine.  There seems to be a random element to the build.  I have also often found weird compile problems can be resolved by doing a clean build, though it's a mystery to me why that should make any difference, given how the build process works.

I think the best thing you could do is EXPLAIN the goofy Arduino build process, as Tim has done in this thread, so people can understand how it works.  It is rather bizarre, and very unconventional.  I was actually unable to find an explanation on-line of how the process works.  The information Tim gave me was invaluable, and I'm amazed I couldn't find an explanation like that anywhere.  Now that I know what it's doing, it shouldn't be hard for me to resolve any further problems that will inevitably crop up.

BTW - One thing that makes fixing these problems more difficult sometimes with VisualMicro is that VisualMicro seems to sometimes not show ALL of the error messages from the compiler.  About once a week, I'll get a compiler error, but NO information to point me to the source of the error.  I can open the Arduino IDE, and compile the same sketch there, and I will always get the missing information.  Perhaps this is a bug with Arduino 1.05, as I've only been using 1.5.6 for a few days now.

Regards,
Ray L.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Multiple File Sketches?
Reply #10 - Jun 17th, 2014 at 1:13am
 
Hi Ray,

Thanks for the info. If you hit any errors that are not resolved correctly and see what they are supposed to be using the Arduino Ide then that will really help thanks
Back to top
 
WWW  
IP Logged
 
RayLivingston
Full Member
***
Offline



Posts: 158
California
Re: Multiple File Sketches?
Reply #11 - Jun 17th, 2014 at 2:05am
 
Tim,

Will do!

Regards,
Ray L.
Back to top
 
 
IP Logged
 
Heinz Kessler
Full Member
***
Offline



Posts: 217
Freiburg, Germany
Re: Multiple File Sketches?
Reply #12 - Jun 18th, 2014 at 6:41am
 
Hi Ray,
thank you for your reply.

My personal recommendation for every project with multiple sources is: Switch to .cpp files and use headers, forget about those .ino files. Arduino tries to do some magic to keep people away from declarations, but the underlying language remains C++, and C++ needs declarations and therefore K&R invented header files.

It's much more convenient to have some well organized headers and to know that every class and function must be declared than relying on the "magic process" of Arduino which Visual Micro tries to imitate.

Heinz
Back to top
 
 
IP Logged
 
RoboBill
Junior Member
**
Offline



Posts: 32
Northern California
Re: Multiple File Sketches?
Reply #13 - Sep 21st, 2017 at 4:10am
 
Wow... just ran across this ...

I've been considering changing IDE's because my program was getting too big and I was looking for other possibilities. (I'm not a programmer)

But this splitting (imitating the Arduino IDE Tabs) is perfect.... many thanks Grin Grin Grin
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print