Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Including shared class from within local sub folder (Read 2116 times)
Andrew (Retro JDM)
Newbies
*
Offline


Posts: 2
Joined: Feb 26th, 2018
Including shared class from within local sub folder
Mar 1st, 2018 at 9:59pm
Print Post  
Hello,

I have a solution with multiple projects. I'd like to use a shared project to store some code.

This all works fine when the folder structure is simple, but when I try to organise my code into sub-folders, I either get errors with the linker, or intellisense.

Here's a bare-minimum example:

My folder structure


Dog.h (a header in a local sub-folder)
Intellisense is happy here, by when I try to compile, I get:
Dog.h: 3:21: fatal error: Pet/Pet.h: No such file or directory


Cat.h (a header in a local sub-folder)
This compiles, but intellisense shows errors


Here's a link to the full solution if you need it:
http://retrojdm.com/Files/shared-project-example.zip

Am I doing something wrong? Is there a way to retain this folder structure and satisfy both the linker and intellisense?

~ Andrew
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Including shared class from within local sub folder
Reply #1 - Mar 2nd, 2018 at 1:57pm
Print Post  
The arduino build system requires the build in a temp folder. Therefore the shared project code is merged into the same temp folder structure as the main project during compilation.

This should mean that your Pet project files will be in the same folder as your main code during compile and #include "Pet.h" should work.

If you created a sub folder below the Pet shared project called "\Pet" and placed all Pet code in or below that folder then your main arduino sketch code include would be #include "Pet/Pet.h"

If you have a sub folder below your main arduino code called \Test containing a Test.cpp then Pet would be included as "../Pet.h" or in my latter example with \Pet sub folder then "../Pet/Pet.h"

The root of all projects should be considered to be the same for all project code and shared projects that are not library projects.
  
Back to top
WWW  
IP Logged
 
Andrew (Retro JDM)
Newbies
*
Offline


Posts: 2
Joined: Feb 26th, 2018
Re: Including shared class from within local sub folder
Reply #2 - Mar 2nd, 2018 at 8:50pm
Print Post  
Thanks for taking the time to explain everything  Smiley

The only nag I have is with intellisense thinking #include "../Pet/Pet.h" is invalid from within Cat/Cat.h. Am I stuck with this?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Including shared class from within local sub folder
Reply #3 - Mar 2nd, 2018 at 9:01pm
Print Post  
You might need to move to library structure. I don't think microsoft expect a shared project to be able to reference another shared project.

However it might work as a library
  
Back to top
WWW  
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Including shared class from within local sub folder
Reply #4 - Mar 3rd, 2018 at 1:31pm
Print Post  
Thinking some more. The Pet project should be a library then all will be well.

Pet will always then be #include "pet.h"

  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint