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


Posts: 22
Joined: Aug 7th, 2019
How to set global include search path?
Aug 7th, 2019 at 4:39pm
Print Post  
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.

« Last Edit: Aug 7th, 2019 at 4:41pm by John2006_ty »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to set global include search path?
Reply #1 - Aug 7th, 2019 at 4:54pm
Print Post  
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


« Last Edit: Aug 7th, 2019 at 4:58pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
John2006_ty
Junior Member
**
Offline


Posts: 22
Joined: Aug 7th, 2019
Re: How to set global include search path?
Reply #2 - Aug 7th, 2019 at 5:47pm
Print Post  
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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to set global include search path?
Reply #3 - Aug 7th, 2019 at 6:17pm
Print Post  
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.
« Last Edit: Aug 7th, 2019 at 6:18pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
John2006_ty
Junior Member
**
Offline


Posts: 22
Joined: Aug 7th, 2019
Re: How to set global include search path?
Reply #4 - Aug 8th, 2019 at 3:31am
Print Post  
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++)
Select All
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++)
Select All
#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?
« Last Edit: Aug 8th, 2019 at 3:43am by John2006_ty »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to set global include search path?
Reply #5 - Aug 8th, 2019 at 11:09am
Print Post  
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
Junior Member
**
Offline


Posts: 22
Joined: Aug 7th, 2019
Re: How to set global include search path?
Reply #6 - Aug 8th, 2019 at 11:21am
Print Post  
Sorry to have missed the Hdr path details. See attached.

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

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

with ../src/ftdi/FT_Eve_Hal/Hdr as global include?
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to set global include search path?
Reply #7 - Aug 8th, 2019 at 11:25am
Print Post  
Yes if you want to stay arduino compatible which is recommended because it avoids confusion.
  
Back to top
WWW  
IP Logged
 
John2006_ty
Junior Member
**
Offline


Posts: 22
Joined: Aug 7th, 2019
Re: How to set global include search path?
Reply #8 - Aug 8th, 2019 at 4:07pm
Print Post  
Tim@Visual Micro wrote on Aug 7th, 2019 at 6: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++)
Select All
#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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to set global include search path?
Reply #9 - Aug 8th, 2019 at 4:17pm
Print Post  
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++)
Select All
-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++)
Select All
#include <FT_Platform.h> 

« Last Edit: Aug 8th, 2019 at 4:19pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
John2006_ty
Junior Member
**
Offline


Posts: 22
Joined: Aug 7th, 2019
Re: How to set global include search path?
Reply #10 - Aug 9th, 2019 at 5:02pm
Print Post  
Tim@Visual Micro wrote on Aug 8th, 2019 at 4: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
« Last Edit: Aug 9th, 2019 at 5:05pm by John2006_ty »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to set global include search path?
Reply #11 - Aug 10th, 2019 at 10:32am
Print Post  
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 TopicPrint