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
Hot Topic (More than 8 Replies) Can not put .cpp and .h files into a subdirectory (Read 2792 times)
Casey
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2014
Can not put .cpp and .h files into a subdirectory
May 27th, 2015 at 2:22am
Print Post  
Hello-

I can not seem to get the compiler to find my files if I put them in a sub-directory.  I'm using Atmel Studio 6.2.1502 and the latest release of Visual Micro. 

I've been creating a lot of classes, so I have a ton of .h and .cpp files hanging around and putting them in a subdirectory would make everything a lot better.  However, all of my attempts to do that have not worked.  Each time I get a compiler error that the subject .h file can not be found (fatal error: xyz.h: no such file or directory.  Error compiling).

So far I've tried the following:
- Adding the relative path in the include: #include "subdirectory/xyz.h".  Intellisense sees the file is there, but the compiler does not.
- Adding the absolute path in the include: #include "/long/path/to/Arduino/project/subdirectory/xyz.h".  Same issues, intellisense is good, but the compiler is not.
- Adding the path to the project: Project/Properties/AVR/GNU C++ Compiler/Directories and adding my main or subdirectory.  This also doesn't work and the added directory disappears after I build or save the project.

Based on that last one, I'm guessing the visual micro is hijacking the includes directories to force the Arduino sketchbook and the Arduino source folders to be included.

Is there any way to include my subdirectory in visual micro?  My project is in the top level of the Arduino (sketchbook) folder, which isn't ideal but perhaps that matters here.

Any help would be greatly appreciated.  Thanks.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can not put .cpp and .h files into a subdirectory
Reply #1 - May 27th, 2015 at 7:29am
Print Post  
Its not allowed in the arduino spec. No sub directories. We are considering adding option though. Will prevent you ever from using the arduino ide
  
Back to top
WWW  
IP Logged
 
Casey
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2014
Re: Can not put .cpp and .h files into a subdirectory
Reply #2 - May 27th, 2015 at 2:15pm
Print Post  
That would explain why I'm having so much trouble.  I think subdirectories would be an excellent feature to add.

I haven't used the Arduino IDE in a long time and I have no plans to ever go back.  I prefer Atmel Studio over Visual Studio (mostly because of being able to program using my Dragon directly from Atmel Studio), but either one in combination with Visual Micro is so much better than the Arduino IDE I'm not sure why anyone would use anything else.

I would definitely like a subdirectories option.  Thanks for the expertise and the quick reply.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can not put .cpp and .h files into a subdirectory
Reply #3 - May 27th, 2015 at 3:11pm
Print Post  
Ok thanks for the update. Do you think it would be okay to elect a root sub folder for additional code such as \src. This might be safer should arduino start to support \libraries or something else under the sketch folder in the future?
  
Back to top
WWW  
IP Logged
 
Casey
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2014
Re: Can not put .cpp and .h files into a subdirectory
Reply #4 - May 28th, 2015 at 12:15am
Print Post  
That's a tricky one.  Ideally I'd like to include any folder anywhere, but what is really important to me now is a selection of folders that are sub folders to the project folder.  For example, I've got a pile of classes (both .h and .cpp files for each) that relate to sending data and having a "sendDataClasses" folder would be ideal.

Having the folders be in the project folder is nice so that when I check the whole thing into source code control all of the files are in one place (and all controlled).  It doesn't matter to me if the paths are added in the files themselves (as paths before the include names) or via a project setting like the compiler directories setting in Atmel Studio/ Visual Studio without Visual Micro.  Perhaps have an option in the visual micro menu that allows various paths to be added (along with a note that this functionality is not supported in the Arduino IDE)?

Thanks again Tim.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can not put .cpp and .h files into a subdirectory
Reply #5 - May 28th, 2015 at 12:40pm
Print Post  
The problem with just adding paths can be that it's not possible to discover and compile the references into .o files. 

Some users report that some includes don't need to be compiled but for Arduino sketch sources they are all compiled into object files in the temp build folder.

My knowledge in this area if weak so I would like to avoid support issues by being in a position to explain the difference between non-compiled include paths and compiled project files. If this is possible to clearly explain then we could have both the include paths and the included source code for compile.

Can you explain anything that would help ??  Smiley

Thanks
  
Back to top
WWW  
IP Logged
 
Casey
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2014
Re: Can not put .cpp and .h files into a subdirectory
Reply #6 - May 28th, 2015 at 7:29pm
Print Post  
Sadly, I'm not that strong here either, so I'm not much help.  In other IDEs (Eclipse, Visual Studio, ...) the include paths can be for the compiler or for the linker.  My files are .cpp and .h files, so they need to be discoverable to the compiler, compiled and then linked via the includes in the other source files... which eventually traces back to the "main" .ino file (which is the one with the same name as the project).

Atmel studio has a feature for this in the Project properties, where I can add the directories visible to the avr-gcc compiler.  However, upon building or saving the list of files is reset so my added directories vanish.  Perhaps this is something visual micro is doing to keep the project "Arduino compatible?"

If this cleanup of the include directories could be removed, then it's up to me, the user, to either leave those directories alone (thus ensuring Arduino compatibility) or to add more folders like I want to do to further organize my .cpp and .h files.

Wow, that was a lot of text.  Please keep in mind I'm not an expert here either.  Thanks again.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can not put .cpp and .h files into a subdirectory
Reply #7 - May 28th, 2015 at 8:02pm
Print Post  
Hi,

Yes Visual Micro has to manage the paths because when the board changes or libraries are added the path list needs to be re-built. However there are some new options that are coming out soon which will allow you to have more control over that.

However the build process and compiler commands are read from the definitions provided by the arduino ide and that governs the compile. There is not auto discovery of files from include paths in the arduino build process however they are working on that from a library perspective but not sure how useful that will be.

I think it will be right to say sources in folders below the sketch will be compiled, additional include paths will only ever be include paths so sources will not be compiled or linked.
  
Back to top
WWW  
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can not put .cpp and .h files into a subdirectory
Reply #8 - Sep 9th, 2015 at 10:00pm
Print Post  
The latest release of Visual Micro allows the Arduino rules to be broken. Code can be in sub folders, the files linked into the solution will be compiled. There is a new "Compatibility" section in Tools>Options which enables the various new features to be disabled if Strict Arduino compatibility is required.

Arduino library sources can also be copied to a designated folder structure below each project. The library sources are compiled and #included in the exact same way as normal Arduino libraries. This means that libraries can be developed and then published/copied to the master Arduino library list and shared within other projects. A new "Add>New Arduino Library" menu item provides a quick way to create a new library but they can also be created manually.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint