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 How do I create an 'Arduino Library' project and include it in another project? (Read 2927 times)
barnold
Newbies
*
Offline


Posts: 7
Joined: Mar 7th, 2015
How do I create an 'Arduino Library' project and include it in another project?
Mar 18th, 2016 at 4:40pm
Print Post  
A good way to develop is to split a program into libraries/modules which can be individually tested and then include those libraries back into a main project. These libraries are program specific and so should live in a project folder and not in the cross project 'Documents\Arduino\libraries' folder. The ideal structure would be something like

MyProgramSolution
  -> MainProject (+ main.ino)
    -> Module1Project (+ test.ino)
    -> Module2Project (+ test.ino)

VisualMicro seems to offer a way to do this since I can create separate 'Arduino Library' projects inside a solution which include a .ino file for testing which is great, however I can't seem to get the main project to include the library files.

I have tried 'Adding a Reference' but no luck as well as, rebuilding/cleaning the project/adding paths in the project preferences etc. and other things but no luck.

What is the best way to do this?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How do I create an 'Arduino Library' project and include it in another project?
Reply #1 - Mar 18th, 2016 at 4:55pm
Print Post  
Not at the moment because I haven't worked out a clean centralized way of handling directories. So input is welcome.

Maybe I misunderstand some of what you have said. I am a little confused by your suggested structure because you still have only one "main project" that could share the libraries

-> MainProject (+ main.ino)
    -> Module1Project (+ test.ino)

Would it make more sense to have?

-> MainProject1 (+ main.ino)
-> MainProject2 (+ main.ino)
-> Libraries
    -> Module1Project (+ test.ino)
    -> Module2Project (+ test.ino)

  
Back to top
IP Logged
 
barnold
Newbies
*
Offline


Posts: 7
Joined: Mar 7th, 2015
Re: How do I create an 'Arduino Library' project and include it in another project?
Reply #2 - Mar 18th, 2016 at 9:55pm
Print Post  
For a cross project library ideally we could create an 'Arduino library project' anywhere in the filesystem but include it in the solution - the include paths would be hooked in by 'Adding a Reference' in the main project. (Right Click -> Add Reference -> Select the library project). If the Arduino library project is created in a standard Arduino library folder then Arduino too will pick up on it.

However the use case I was describing is a way to make .cpp/.h files along with an .ino for testing that can be easily selectively deployed. So far I've found the best thing to do is to create the .cpp/.h files and create .ino files for each and wrap the .ino files in `#ifdef`s so they can be selectively compiled, however this is kind of awkward to manage.
« Last Edit: Mar 18th, 2016 at 10:24pm by barnold »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How do I create an 'Arduino Library' project and include it in another project?
Reply #3 - Mar 18th, 2016 at 10:17pm
Print Post  
Hi thanks for explaining and that makes sense. I need to give it more thought.

I have one suggestion but I don't know how well it will work for you.

Currently you will have library code in "MainProject1\src\libraries\Module1\src"

You could create an arduino project or put a Module1.ino in "MainProject1\src\libraries\Module1" then open it. 

Right click include the Module1\src files into the Module1 project using the VS solution explorer

Then add relative #includes for the src sources in the Module1.ino. 

#include "src/Module1.h"

The #include(s) will allow visual micro to compile the Module1\src code (but it will be treated as local sketch code and not a library which is why I am not sure how well it will work for you).

You will end up with a solution explorer that has a "Module1" test project alongside "MainProject1". 

"MainProject1" wiill use the standard Arduino library #include "Module1" which the Module1 project will map directly to it's \src code.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint