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
How to set global include search path? (Read 508 times)
John2006_ty
Newbies
*
Offline



Posts: 9
How to set global include search path?
Aug 7th, 2019 at 5:39pm
 
I have a project with folder hierarchy as below:

project root\
                 \components
                 \components\ftdi
                 \components\ftdi\FT_Esd_Framework
                 \components\ftdi\FT_Esd_Widgets
                 \components\ftdi\WidgetOpacity
                 \components\lcd
                 \helloworld.ino

Project structure looks like attached jpg (projStructure.jpg)

By expansion on one of the folders it shows all files with red bar icon (file_redbar.jpg), that means they cannot be included.

Is there any way I can set global include search paths for this project?

I tried right click on project properties > VC++ Directories > Include Directories > ..\components\ftdi\FT_Eve_Hal\Hdr; .... but still include paths not set.

Back to top
« Last Edit: Aug 7th, 2019 at 5:41pm by John2006_ty »  

projStructure.jpg (32 KB | 1 )
projStructure.jpg
file_redbar.jpg (43 KB | 1 )
file_redbar.jpg
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: How to set global include search path?
Reply #1 - Aug 7th, 2019 at 5:54pm
 
Hi,

You have to use the structure published by arduino.cc. An arduino project can only have code in an \src sub folder or any folder below that.

So in your case that would mean moving the components to be src\components

There are other options for shared code from other locations and arduino libraries but best to avoid until you have a clear understanding of what can be done within the arduino standard.

There is also option to set compiler -I include path for project or solution but the compiler include paths would not cause code in the included folders to be compiled.

All of the VS property page options except for intermediate and final build paths should be treated as readonly so that we can force VS intellisense to work. When a build happens the project properties are not used because they don't make a lot of sense for arduino. Visual micro handles the build and leaves vs to manage the intellisense after feeding it paths.

We are considering extending visual micro to give you simple paths to add to a config file that allows external code to be included but it will probably cause more complications than what it would solve. The point that people miss is that for multiple .ino files to be supported they are actually combined into a .cpp in background when the build happens. That means we have to build in a hidden temp folder which blows the concept of allowing people to include other sources simply because noone would ever know what the #include <relative path?> would be.

As I have said there are options for external code in terms of shared code projects or arduino compatible libraries but you do need to fully understand the way arduino works before using those options.

The simplest solution is to work from the \src sub folder of your project and then all your #includes will be relative and obvious. It is also supported to put the .ino files in the \src folder instead of the project folder, in this case your #includes (from .ino to components sub folder) would avoid needing \src\ and would be as you already have them.

I hope this helps


Back to top
« Last Edit: Aug 7th, 2019 at 5:58pm by Visual Micro »  
WWW  
IP Logged
 
John2006_ty
Newbies
*
Offline



Posts: 9
Re: How to set global include search path?
Reply #2 - Aug 7th, 2019 at 6:47pm
 
Hi

Do you mean I need to follow strictly the way an Arduino library is structured? In the sense that I have to put components directory to ../Arduino/libraries/src/components/...?

Actually I could rename components > src so that the folder structure becomes :

src/ftdi/FT_Esd_Framework, etc.

But I cannot put it to the Arduino library directory because all files are created from a PC software for each project. I don't have control on it. That means they will be different from case to case. It has to be a part of the .ino project, reside in the same level as .ino main sketch.

Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: How to set global include search path?
Reply #3 - Aug 7th, 2019 at 7:17pm
 
Arduino supports \src below each sketch. This means each project can have \src folder with sub folders below it. This has no relation to libraries.

If you click File>New>Project you will see there is an empty Visual Micro project with the \src folder included for you along with a readme file that explains how arduino works with sub folders.
Back to top
« Last Edit: Aug 7th, 2019 at 7:18pm by Visual Micro »  
WWW  
IP Logged
 
John2006_ty
Newbies
*
Offline



Posts: 9
Re: How to set global include search path?
Reply #4 - Aug 8th, 2019 at 4:31am
 
I see. Starting over with a new project created with folders and source files manually copied to /src. I had to click right on the folder under solution workspace and set <Include In Project> to remove the red bar sign, that means the files are now properly included in compile process, I think.

Project structure is like screen shot attached.
I have trimmed down the project so that ONLY the HAL drivers are included.

From [Properties] > [Configuration Properties] > [C/C++] > [Additional Include Directories]  I have set two new paths to point to src/ftdi/FT_Eve_Hal/Hdr and
src/ftdi/FT_Eve_Hal/Hdr/Teensy.

A project rebuild gave me an error:

Code (C++):
FT_CoPro_Cmds.cpp: 31:25: fatal error: FT_Platform.h: No such file or directory
   compilation terminated 



In FT_CoPro_Cmds.cpp it is like:

Code (C++):
#include "FT_Platform.h"

void Ft_function_A(void);
void Ft_function_B(void);
... 



The error message shows that 'include path' has not been set properly. This folder hierarchy was good in Eclipse. But how it is set in VS?

Any suggestion?
Back to top
« Last Edit: Aug 8th, 2019 at 4:43am by John2006_ty »  

proj_struct.jpg (67 KB | 1 )
proj_struct.jpg
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: How to set global include search path?
Reply #5 - Aug 8th, 2019 at 12:09pm
 
As I said the c++ vs properties are managed by visual micro. You can not change them to any useful effect.

You can click a project name and press F4 then see the compile flags where you can add -I includes however I think you should keep things arduino compatible

Your include example below #include "FT_Platform.h" is not shown in the source code image so it's hard to give you help. I can tell you that the project path is set as a compiler include by both the arduino ide and visual micro. So your .ino code can reference #include "src/ftdi/FT_Eve_Hal/Hdr/FT_Platform.h"

note there is a bug fix around #includes with relative paths available from the 1908.7 work in progress here https://www.visualmicro.com/forums/YaBB.pl?board=VS_ARDUINO_EXT_RELEASES
Back to top
 
WWW  
IP Logged
 
John2006_ty
Newbies
*
Offline



Posts: 9
Re: How to set global include search path?
Reply #6 - Aug 8th, 2019 at 12:21pm
 
Sorry to have missed the Hdr path details. See attached.

You meant I need the full path Code (C++):
#include "src/ftdt/..../FT_Platform.h" 

instead of Code (C++):
#include "FT_Platform.h" 

with ../src/ftdi/FT_Eve_Hal/Hdr as global include?
Back to top
 

Hdr_full_paths.jpg (63 KB | 1 )
Hdr_full_paths.jpg
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: How to set global include search path?
Reply #7 - Aug 8th, 2019 at 12:25pm
 
Yes if you want to stay arduino compatible which is recommended because it avoids confusion.
Back to top
 
WWW  
IP Logged
 
John2006_ty
Newbies
*
Offline



Posts: 9
Re: How to set global include search path?
Reply #8 - Aug 8th, 2019 at 5:07pm
 
Visual Micro wrote on Aug 7th, 2019 at 7:17pm:
Arduino supports \src below each sketch. This means each project can have \src folder with sub folders below it. This has no relation to libraries.


Didn't know that. Learning something new today. Thanks a lot.

Now I have changed it to relative path like code extract below the project does compile OK.
Code (C++):
#include "../../Hdr/FT_Platform.h" 



But the relative path seems a bit messy. When there is a lot of sub-folders below /src the layers of relative search path becomes difficult to follow. It is Okay. I can simply the folder structure so that all .cpp and .h reside in a single folder to make life easier.

Thanks a lot.

Remarks: I have tried Sloeber with this project under Eclipse. Compile time with vmicro in VS is much faster than Eclipse, although the same teensy compiler toolchain is used. Interesting.

Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: How to set global include search path?
Reply #9 - Aug 8th, 2019 at 5:17pm
 
Thanks for the update.

A non-arduino compatible way to add your includes might be to click "vMicro>Project Properties" and add the following as a compiler>extra flags:-

Code (C++):
-I"{sketch_path}/src/..../hdr" 



note: {sketch_path} is a build variable. You can see all the build variables in the verbose output when "show build properties" is enabled.

Then hopefully both intellisense and the compiler will be happy with

Code (C++):
#include <FT_Platform.h> 

Back to top
« Last Edit: Aug 8th, 2019 at 5:19pm by Visual Micro »  
WWW  
IP Logged
 
John2006_ty
Newbies
*
Offline



Posts: 9
Re: How to set global include search path?
Reply #10 - Aug 9th, 2019 at 6:02pm
 
Visual Micro wrote on Aug 8th, 2019 at 5:17pm:
A non-arduino compatible way to add your includes might be to click "vMicro>Project Properties" and add the following as a compiler>extra flags:-


I am convinced by you that it would be better to make it "Arduino compatible". Now the project restructured with all .cpp and .h files grouped in a single folder to make life easier. Screenshot attached shows fours folders under /src/ftdi, containing some graphical framework, widgets, hal, and application. In this way I can compile the project with an .ino file in VS + Vmicro and it is to my surprise, conventional Arduino IDE also compiles this project without problem. Both compile and run OK in hardware.

Thanks a lot for your advice.

John
Back to top
« Last Edit: Aug 9th, 2019 at 6:05pm by John2006_ty »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: How to set global include search path?
Reply #11 - Aug 10th, 2019 at 11:32am
 
Great thanks for the update, yes I agree. Staying within the Arduino framework is the best solution.
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print