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 Library or Shared Code projects - putting code in a Source subfolder (Read 2099 times)
HughMacd
Newbies
*
Offline


Posts: 6
Location: London, UK
Joined: Sep 11th, 2018
Library or Shared Code projects - putting code in a Source subfolder
Sep 11th, 2018 at 3:29pm
Print Post  
Hi,

I'm just in the processes of starting to test out the Arduino VS2017 plugin.

In my solution, I currently have (for testing purposes) two projects:

  • MyProject (an Arduino Project)
  • MyLibrary (an Arduino Library Project)


For the folder structure for these, I'm wanting the following:

Code
Select All
$(SolutionDir)\MyProject\ (the root of the main project)
$(SolutionDir)\MyProject\Source\MyProject.ino
$(SolutionDir)\MyLibrary\ (the root of the library project)
$(SolutionDir)\MyLibrary\Source\*.cpp *.h 



I can set up the reference from MyProject to MyLibrary, but from within MyProject, I want to be able to do:

Code
Select All
#include "MyLibrary.h" 



However, it seems to want me to do:

Code
Select All
#include "Source/MyLibrary.h" 



Is there anything that I can do in MyLibrary to tell it that the files that should be referenced are within the Source folder?

If I open up the MyLibrary.vcxitems, there is a line that says:

Code
Select All
irectory)</AdditionalIncludeDirectories> 



I tried changing that by hand to read:

Code
Select All
irectory)Source</AdditionalIncludeDirectories> 



But that didn't seem to make a difference.

I also tried going into the project properties for MyProject and changing

Code
Select All
$(ProjectDir)..\MyLibrary 



to

Code
Select All
$(ProjectDir)..\MyLibrary\Source 



But that also did not seem to make a difference.

Is there any way of doing this?

Thanks
« Last Edit: Sep 11th, 2018 at 4:44pm by HughMacd »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Library or Shared Code projects - putting code in a Source subfolder
Reply #1 - Sep 11th, 2018 at 4:35pm
Print Post  
Hi,

I think you need to step back and understand how arduino libraries work.

They do not have .ino files.

You also need to ignore standard vs properties for includes etc they don't make sense for arduino.

Use visual micro to add existing arduino libraries as shared projects so you can understand the structure of an arduino library. Then revisit this question.

An arduino library will also be #included without a path.

  
Back to top
IP Logged
 
HughMacd
Newbies
*
Offline


Posts: 6
Location: London, UK
Joined: Sep 11th, 2018
Re: Library or Shared Code projects - putting code in a Source subfolder
Reply #2 - Sep 11th, 2018 at 4:44pm
Print Post  
Hi Tim,

It looks like my first code block was slightly malformed - the .ino was meant to be in the Project, and the .cpp/.h files in the Library. I've changed that.

I've a pretty clear understanding of how Arduino projects/libraries work. All I'm after doing here is figuring out a way of having my code in a "Source" folder inside the project, instead of at the root of the project. Maybe my question was a little long-winded, but with the exception of the typo at the very top (and I can see how that would have been confusing!), I was trying to show that I had investigated every option I could think of.

I can definitely see that this is incredibly useful, and have purchased a commercial license, as I will certainly be using it more over the coming months, but I'd like to get my head around what I can do with the folder structure at the start, before I get too much further into it.

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


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Library or Shared Code projects - putting code in a Source subfolder
Reply #3 - Sep 11th, 2018 at 4:52pm
Print Post  
Okay that's a relief about the .ino

Arduino lib code needs to be in the root of the lib or in the \src folder below the lib project. The library should ideally have a .h file of the same name as the containing folder.

A library that is a shared project can be located anywhere and will be included simply with #include "mylib.h" but make sure you follow the arduino rules concerning library design and folder structure.

Make sure you follow the readme in the example projects that says to add a reference from the arduino project to the shared project. Right click References in the arduino project and choose Add, then you will see a tab called "Shared Projects" showing your shared projects. Click the checkbox against your lib project and click OK


« Last Edit: Sep 11th, 2018 at 4:54pm by Tim@Visual Micro »  
Back to top
IP Logged
 
HughMacd
Newbies
*
Offline


Posts: 6
Location: London, UK
Joined: Sep 11th, 2018
Re: Library or Shared Code projects - putting code in a Source subfolder
Reply #4 - Sep 11th, 2018 at 4:54pm
Print Post  
Ah - "src" - that works for me.

I've got the reference working fine - everything is good apart from the folder, so knowing that I can use a "src" folder makes me happy!

Thanks for your help.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Library or Shared Code projects - putting code in a Source subfolder
Reply #5 - Sep 11th, 2018 at 5:00pm
Print Post  
Great, thanks for buying.

You can also use sub folders below \src for code private to the lib
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint