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) Difficulties with Include File Paths (Read 9493 times)
Paul R. Potts
Newbies
*
Offline


Posts: 4
Joined: Mar 27th, 2015
Difficulties with Include File Paths
Mar 27th, 2015 at 3:23pm
Print Post  
Hello,

I have a sketch that builds fine with the Arduino 1.6.1 IDE. I am trying to use the Visual Micro plugin to allow me to turn this into a more complex project that supports a number of .h and .cpp files so that I can break the code into components. Just for context, I am very comfortable with C and C++, IDEs and command-line tools; if I need to migrate entirely to a command-line build I will do that. My hope for now was to be able to continue to use an .ino file for the top layer and link with the rest of the code contained in .cpp/.h files.

Right off the bat I am having trouble. The Arduino sketch has an include file right alongside the .ino file in the sketch directory. When I create a Visual Studio 2013 solution & project, though, this include file can't be found from the .ino file.

If I examine the project Property Pages for the currently active configuration (Debug), I can see the Include Directories. Initially it contains only $(VC_IncludePath);$(WindowsSDK_IncludePath); which are inherited values.

I added $(ProjectDir) and expected that this would fix the problem, since the file I am including is alongside the project file as well. I am accustomed to having to specify paths for include files and libraries, either in an IDE or Makefile.

However, this doesn't work.

It occurs to me that maybe these standard Visual Studio project property pages don't play a part in the building up the include paths that are passed to the AVR GCC. In the project properties pane under Extra Flags - Project I place -I "C:\..." (the full path to the directory containing the project file, .ino file, and .h file), but this does not work either.

There must be a way to do this. I am going to want to build .cpp files with headers in multiple directories, with relative paths if possible. Where would I specify those paths?

Thanks,

Paul R. Potts

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


Posts: 12167
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Difficulties with Include File Paths
Reply #1 - Mar 27th, 2015 at 3:33pm
Print Post  
Hi,

This might be a case of too much knowledge Smiley

You are right you can ignore every standard Visual Studio project property they have nothing to do with the Arduino build and are used by Visual Micro only to make intellisense work.

It's possible that Visual Micro is not managing the project. How did you create the project?

If you click "build", what output is shown?

Thanks

ps: You have to use arduino libraries if the code is not in the main sketch folder. The arduino ide also works this way and Visual Micro only supports compatible arduino builds
« Last Edit: Mar 27th, 2015 at 3:46pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Paul R. Potts
Newbies
*
Offline


Posts: 4
Joined: Mar 27th, 2015
Re: Difficulties with Include File Paths
Reply #2 - Mar 27th, 2015 at 3:50pm
Print Post  
Tim@Visual Micro wrote on Mar 27th, 2015 at 3:33pm:
It's possible that Visual Micro is not managing the project. How did you create the project?

If you click "build", what output is shown?


I used the plugin to create a new sketch project.

I will delete everything but the .ino file and the .h file and try again:

1. launch Visual Studio 2013
2. File/Open/Sketch Project
3. Select the .ino file
4. A solution is created
5. Select the project (under the solution), choose build
6. Output is "Compiling 'project' for 'Arduino Yun', project.ino:2:27: fatal error: header.h: No such file or directory

Hmmm... I just realized that I should try #include "header.h" instead of <header.h> and that built. So that is working -- looks like it was my fault.

Still, can you tell me -- is there a way to add include paths to the command line passed to the compiler? Because I will need to specify additional paths somehow.

Thanks,

Paul

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


Posts: 12167
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Difficulties with Include File Paths
Reply #3 - Mar 27th, 2015 at 3:52pm
Print Post  
You can only use legal arduino libraries if outside of the sketch directory.

This is how arduino works and Visual Micro only supports what the Arduino Ide supports.

We are considering adding some additional include paths option but I am not sure how the object files would be built. It might get too complicated and too difficult to support users working outside of the arduino norm,

« Last Edit: Mar 27th, 2015 at 3:53pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Paul R. Potts
Newbies
*
Offline


Posts: 4
Joined: Mar 27th, 2015
Re: Difficulties with Include File Paths
Reply #4 - Mar 27th, 2015 at 3:59pm
Print Post  
You mean I can't add arbitrary C++ files to the project?

If I add a sketch library (a folder with a .cpp and .h file in it) the project somehow now makes reference to the .cpp file, and so it will be included in the build. But it does not show up in the project's list of source files. So how can I see what I am doing? For example, to remove the sketch library? I am willing to place my code in progress into sketch library folders but if I don't have any fine-grained control over what files are built, that is going to make things very difficult to work with as I develop and refactor the code in those libraries.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12167
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Difficulties with Include File Paths
Reply #5 - Mar 27th, 2015 at 4:02pm
Print Post  
You can click/select the project then on the project MENU look for an option called "Show sketch core and library sources". This toggles the lib sources into the project as short cuts so you can see them and work with them as normal. 

The project is just for your editing/use, the compile will look at the disk and do a normal arduino compile.

They are normally hidden to avoid new user confusion.
« Last Edit: Mar 27th, 2015 at 4:02pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Paul R. Potts
Newbies
*
Offline


Posts: 4
Joined: Mar 27th, 2015
Re: Difficulties with Include File Paths
Reply #6 - Mar 27th, 2015 at 4:14pm
Print Post  
Ah! OK. It looks like that is enough to get me going. It sounds like a possible workflow then is to add .cpp files that are alongside the .ino file, then once I am satisfied that they work, migrate them into Sketch library folders.

I'm basically trying to do a sort of compromise between using the Arduino IDE that does not give me enough control and does to much behind the scenes for me, and using a straight-up AVR project in Atmel Studio. So if this will let me do that, and still use Visual Studio 2013, it's all good. Thanks!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12167
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Difficulties with Include File Paths
Reply #7 - Mar 27th, 2015 at 4:28pm
Print Post  
Ok,

If you attempt to move lib code to the sketch folder you will probably need to remove the library or the compiler might still pick it up.

The "tools>visual Mirco>reload toolchains" can be used to force vm to re-scan libraries

The "Project>show sketch core/lib sources" is a toggle, so click twice to refresh the Ide libs list if you add new sources to a lib from outside of the ide.

It's not ideal but these tips might be useful at some stage
« Last Edit: Mar 27th, 2015 at 4:29pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12167
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Difficulties with Include File Paths
Reply #8 - Sep 9th, 2015 at 10:01pm
Print Post  
The latest release of Visual Micro allows the Arduino rules to be broken. Code can be in sub folders, the files linked into the solution will be compiled. There is a new "Compatibility" section in Tools>Options which enables the various new features to be disabled if Strict Arduino compatibility is required.

Arduino library sources can also be copied to a designated folder structure below each project. The library sources are compiled and #included in the exact same way as normal Arduino libraries. This means that libraries can be developed and then published/copied to the master Arduino library list and shared within other projects. A new "Add>New Arduino Library" menu item provides a quick way to create a new library but they can also be created manually.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint