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
Sharing Arduino code between projects (Read 155 times)
Flint
Newbies
*
Offline



Posts: 4
Sharing Arduino code between projects
May 13th, 2020 at 4:40pm
 
Hello.
in post https://www.visualmicro.com/post/2016/05/27/Sharing-code-between-projects.aspx
you wrote: "NOTE: Click the "Add as link" option when adding the code"
where i can find this option?
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10653
United Kingdom
Re: Sharing Arduino code between projects
Reply #1 - May 13th, 2020 at 5:14pm
 
Thanks for the post. The article has been updated.

Quote:
In more recent IDE's such as Vs2017/2019 use "Add Existing Item" which automatically creates the link to the source.

Tip: After you add files, click the file and press F4 to see if a file is local to the project or shared.
Back to top
 
WWW  
IP Logged
 
Flint
Newbies
*
Offline



Posts: 4
Re: Sharing Arduino code between projects
Reply #2 - May 13th, 2020 at 5:42pm
 
yes i use VS2019.
i have one more question:
after add file to second project i  include .h file in this project .ino file, but take compiller error: "Test2.ino: 7:10: fatal error: ./../Test1/src/TestClass/MyTest.h: No such file or directory
   #include "./../Test1/src/TestClass/MyTest.h""
i attach test solution.
thank you
Back to top
 

TestSln.zip (9 KB | 0 )
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10653
United Kingdom
Re: Sharing Arduino code between projects
Reply #3 - May 13th, 2020 at 5:45pm
 
Use shared projects for cpp/h code. Use add existing for .ino code.

Documentation Available Here
Back to top
« Last Edit: May 13th, 2020 at 5:50pm by Simon Hopkinson »  
WWW  
IP Logged
 
Flint
Newbies
*
Offline



Posts: 4
Re: Sharing Arduino code between projects
Reply #4 - May 13th, 2020 at 6:04pm
 
it's not a Shares Code Project. both are standart "Ardino project" like in you document https://www.visualmicro.com/post/2016/05/27/Sharing-code-between-projects.aspx you add .cpp and .h file not .ino
I try use sared code project, but i can't add library to this project type
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10653
United Kingdom
Re: Sharing Arduino code between projects
Reply #5 - May 13th, 2020 at 7:09pm
 
You can add #includes for libraries to shared projects and they will be discovered. If you don't know which includes to add then add the library to your .ino and then grab the #includes. You can remove the #included from the .ino after that but they will not do any harm.

If you need more help it is important to show the code you have used to add #includes to your add existing > shared code.
Back to top
 
WWW  
IP Logged
 
Flint
Newbies
*
Offline



Posts: 4
Re: Sharing Arduino code between projects
Reply #6 - May 14th, 2020 at 6:14am
 
Thank you.
so, as i understand i can't include .h files from from location that not in references project?
for example i can't create "c:\Common Include" folder for h files that commons for all my projects?
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10653
United Kingdom
Re: Sharing Arduino code between projects
Reply #7 - May 14th, 2020 at 12:58pm
 
Yes that is best, but also on the vMicro>Compiler menu you can enable the project folder -I include. This would then mean that the project folder is a compiler include path and .h files can be referenced as relative paths from that point...

For example:-

Project with include path = c:\foo\bar\MySketchProject

Allows for "..\SomeBarFolder\MyHeaders\Header1.h"
Allows for "..\..\SomeCFolder\MyHeaders\Header1.h"


Using the include path applies only to headers (.h). Files that need to be compiled to object files such as .cpp must be in shared project or the project.
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print