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] 2  Send TopicPrint
Locked Topic Problem with include files (Read 24396 times)
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Problem with include files
Feb 16th, 2016 at 4:53pm
 
Hello folks. I'm returning to programming from a number of years hiatus. I Programmed in C++, C# for quite a number of years. With that being stipulated I believe I might be going insane here. 

I have never in my life of programming ever had so many issues with a compiler not finding include files.

I used Visual Studio for any years and it has changed considerably in the past few years but builds are still builds.

I have told Visual Studio under Project\Properties where include and source directories are located.

I have added the files via Visual Micro, etc. 

Every time I compile I get "Can't find file or directory" I was at this for many hours yesterday and I would be a liar if I didn't admit that I came fairly close, at 47 years old, to putting my fist through my monitor...

I have googled, searched, etc. I have found snippets of people having this problem, one gentleman insinuating its because of the Visual Micro addon etc.

I'm going now to make the most basic of C++ projects to see if I can have includes "WHEREVER I DAMN WELL WANT THEM" and see if Visual studio quits giving me this ridiculous error.

SO I'm here asking all of you old and new pros. Am I missing something simple? I mean I actually enjoy debugging and figuring our logic errors in code. I do not enjoy, in the least, losing many hours of productive time trying to get a compiler to do the most simple of tasks - like find its darn source files...

Any help would be appreciated... deeply...

Thanks very much...
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #1 - Feb 16th, 2016 at 5:14pm
 
Hi Rod,

Visual Micro is doing the right thing the issue is that you have not taken the time to understand how Arduino works. 

Arduino has clear rules that make it easy for users of all experiences to program. It's true that the simplicity of arduino can also confuse some experienced c++ programmers.

Visual micro is only active with arduino .ino/.cpp projects so can not cause a problem with paths in standard visual studio cpp projects.

Visual micro does allow some of the arduino rules to be broken but I wouldn't want to discuss them before discussing the standard arduino compatible ways to work.

It doesn't make sense for you to alter source paths yourself unless you would rather code the entire build process yourself.

If you have some clearer example of what you are trying to achieve I will try to help but before using visual micro I suggest you learn arduino by using the arduino ide for a few days/week. After that I will be happy to explain how to extend the arduino rules in VS.
« Last Edit: Feb 16th, 2016 at 5:28pm by Tim@Visual Micro »  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #2 - Feb 16th, 2016 at 6:06pm
 
Hi thanks for the reply. I have been using the Arduino IDE for weeks while I was learning to use the ATMEL microcontroller, etc. Never had any problems in that IDE at all..

All of the issues started as soon as I decided I needed to write a number of classes to develop a small "engine" that I'm writing for a project. The INO file system didn't seem to be all the robust in a multi-file project. So it was this consideration and having intellisense again that caused me to shift away from the more simple Arduino IDE to Visual Studio and Visual Micro...

If this is indeed an issue that is caused by using Visual Micro then can we work on a sticky post together that will be edited to be clear and concise as to what Visual Micro is doing to the build process that is seemingly breaking the entire Visual Studio build process.

I think it would be good to have a permanent post that clarifies why it happens and how to fix it. I'd be happy to donate some hard earned $$$ to this project if so. If I could have the product working I feel it is well worth purchasing and not just for the debugging unit...

Though here if I was to purchase the debugging unit (I did) I wouldn't be able to think about using it until I could get code to compile...

The odd thing is with this is that one Arduino project that I was in prodding and pushing and entering paths in for hours suddenly was able to compile. I was like "Praise the Silicone" and made a new project to duplicate the working functionality. Nope. Same thing... So what is even more frustrating is it suddenly working and having no bloody clear idea as to why..

I don't understand how it seems that Visual Studio intellisense can be working after an #include "whatever.h" but the linking process is oblivious...

This is a bad problem for a consumer as there seems to be no clear path to a solution... At least not one that I have found that makes sense... I've seen many "try this" type posts but this shouldn't be some weird esoteric compiler issue that requires this kind of blind, stabbing and flailing in the dark to make things work. Probably the only thing that frustrates me is trying to solve a problem that is clearly not straightforward in the "why" it is there in the first place. 

Again thanks  very much for your help. I appreciate if you can help me get past this so I can get coding... This fighting with the "tools" thing is frustrating. I want to be fighting the problem domain - not the tools.  Grin

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


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #3 - Feb 16th, 2016 at 6:16pm
 
Hi,

Thanks for the info. Maybe you should start at the beginning and simply explain what problem you are having.

You say you want to set your own paths and you say the arduino ide works.

That doesn't make sense to me because you can't set any paths in the arduino ide other than the sketchbook folder.

Visual micro out-of-the-box works exactly the same way as the arduino ide and you do not need to set any paths other than the location of the arduino ide and the optional sketchbook folder

If you select the wrong ide version when specifying the arduino location in visual micro then you will get some path issues. So you should explain your config or post a verbose output so we can see what you are seeing.

If you have specified a sketchbook location in visual micro but not in the arduino ide then visual micro will look in a different location to the arduino ide for your arduino user libraries (shared code). This would result in path confusion because the sketchbook location is important for these things (it's how arduino works)

So you shouldn't have to specify any paths other than ide location to have visual micro compiling and uploading the way arduino does.

You opened this thread stating that you should be able to set compiler paths to point wherever you please. I feel that is a deeply confusing statement when compared with your subsequent statement that things work fine in the arduino ide. It should work the same in Visual Micro.

Please be clear. 

Does the blink example compile okay? 
Can Visual micro open and compile sketch projects that were created in the arduino ide?
Can you add #includes to libraries (use the visual micro menu/bar), does the code continue to compile okay?




« Last Edit: Feb 16th, 2016 at 6:17pm by Tim@Visual Micro »  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #4 - Feb 16th, 2016 at 7:35pm
 
Hi there. In your first post to me you asked if I had used the Arduino IDE. I replied that yes I had, I didn't say, however, that I had setup multiple directories, etc. there. I think you made this assumption and I'm sorry if somehow I led you there but I went back and read what wrote and I think I'm being fairly clear as to what I was and am doing now..

I said as you can see above it was the "wish" for this and "intellisense" that had me move to the "Visual Studio IDE" with "Visual Micro" as an add on.

So we are not talking about working in the Arduino IDE at all and using only .INO files all in the same directory.

We are talking about using Visual Studio. I want simply to have the "ONE" required sketch file and then the rest of my files all traditional .H and .CPP files. Many of these files are as a C++ programmer would, stored in directories that represent possible future library builds. 

If I have the simplest of projects..

SKETCH_A.INO
SKETCH_A_MAIN.CPP
SKETCH_A_MAIN.H

All I would have is the required #includes in the .INO file. 

Setup, Loop, code entry point, etc. is in the SKETCH_MAIN_CPP.

What isn't clear to me is do all of my #includes have to be in this one file? I can't see why normal processing of .CPP and .H files is interrupted because of using Arduino. This seems to me to be counter intuitive and makes no sense. 

I'm sorry if I'm missing something basic and seem incoherent and stupid to you... 

I just have written hundreds of thousands of C++ code and have seen some pretty ugly make files in my day and this 15 lines of test code not compiling because it can't find header and source files is maddening.... 

So I do please ask you be a bit patient with me as I have been trying to get these 15-20 lines of code to work for hours. You obviously know this feeling as anyone in this business does and would be foolish to say other. Sometimes just asking some peers to shed light on something you have been staring at for many hours is all you need. 

Obviously I have tried <> and "". Years ago we only used <> for standard libraries and "" for in house. Not sure what is done today but I will probably code this project as such as I'm familiar with that. 

The point is that after telling Visual Studio in EVERY BLODDY place I can find to stipulate where my source and header files are I still get...

Can't find file or directory compile terminated... Though intellisense seems to be recognizing them - that actually makes it more maddening - not less no. I would prefer it not to work at all. This just seems flaky...

Still now today 30 hours later. I'm in the same place and would really love to just get my project going...

I understand that I may be missing something simple as I'm new with Arduino. I read somewhere, couldn't find the link again, that ALL of the includes have to be in the main .INO file? 

This seems to me to be really stupid and I'm presuming it is done to retain some compatibility with going back to the Arduino IDE?

I have no intention of ever going back to the Arduino IDE as I wouldn't have gone to all this trouble unless I had a desire to break the project into components as I do. 

With this being said is there an option that says, enough of this foolish trouble to retain compatibility with the Arduino IDE. I'm planning on staying here so how can I stop doing all this special stuff to satisfy those conditions and just work.


I'm writing software to articulate some interactive sculpture. The software will eventually be fairly complex as I'm writing it in an "engine" fashion so as it can be used on future projects with multiple installations. Can't really say much more. lol....

Hard to get to that point when simple empty files devoid of any real code, just stubs, won't compile because of some weird issue I can't seem to wrap my mind around...

http://www.visualmicro.com/post/2014/01/13/How-to-Create-Arduino-Projects-In-Vis...

I'm recreating this project again. I'm very sure that I followed this post to the letter before but ..... giving it another shot here before I go walk off some steam.

Not sure if I was more clear this time. I just slept for a couple hours in my studio\office and I'm back at it. Pretty tired and annoyed old fart here....


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


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #5 - Feb 16th, 2016 at 7:47pm
 
Hi,

Okay makes sense thanks.

The first rule is for where code must reside, the setup() and loop() methods must reside in an .ino file.

The second is that using [project_name].cpp as a file name confuses the build process because arduino .ino files are combined into a file of that name during the build process (in a temp folder).

I think if you rename SKETCH_A_MAIN.CPP and SKETCH_A_MAIN.H to PROGRAM_A_MAIN.CPP AND PROGRAM_A_MAIN.H you will avoid a lot of confusing issues.

After doing so #includes for code in the same folder will simply be #include "file.h", in sub folders will be #include "folder\folder2\file.h"

If you have code that doesn't need to be compiled but exists outside of the project then you can force compiler includes via the "visual micro>project properties>extra flags" using -I"c:\folder1" -I"c:\folder1" however doesn't sound like you need this.

  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #6 - Feb 16th, 2016 at 8:25pm
 
In this link;

http://www.visualmicro.com/post/2014/01/13/How-to-Create-Arduino-Projects-In-Vis...

it says;

'The only rules are the Arduino rule which state that an Arduino sketch must contain a .ino file of the same name as the folder. In Visual Studio the project must also have the same name as the folder and the .ino'

Are you and this quote saying the same thing?

I want to be able to use.

Project\Properties\VC++ Directories\Include Directories
Project\Properties\VC++ Directories\Source Directories

I would like to put "Look here" for these ".H
and .CPP files.

Look here for these files... etc. like in an old make file. I had no idea that people where using explicit paths in their include statements. I thought this was bad practice and have never done so. I have always told the compiler where everything is either through properties in the Visual Studio IDE or via make files (which admittedly I haven't done for years - just relearning Bourne Shell scripting lately reminds me of things I don't like)   

This is exactly what I'm doing and I can't see why it doesn't work. 

Thanks for hanging in there and being patient with me...

Cheers
 





  
Back to top
 
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #7 - Feb 16th, 2016 at 8:29pm
 
So went through this again and still...

;-( I just don't know how anything so simple could eat so many hours of my life....

Compiling debug version of 'EntryPoint' for 'Arduino/Genuino Uno'
EntryPoint.ino:2:32: fatal error: sonic_range_finder.h: No such file or directory
:#include <sonic_range_finder.h>
:compilation terminated
Error compiling project sources
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #8 - Feb 16th, 2016 at 8:33pm
 
You can't use the official c++ source and header directories properties. It would be too difficult to keep the automated side of the arduino compatible build process in conjunction with those paths. maybe something for the future.

The hard coded paths that visual micro maintains can be hard coded because they are automatically updated and always correct.

The compiler include paths in my example where simply an example, relative paths are also okay and env vars also prob work but you need to understand that the arduino build process only produces .o object files for known code such as project library or core code.

You can add file shortcuts to the project with shared code and you can use local arduino libraries below the project and of course sub folders below the sketch/project. That's all it's a fine line between keeping compatibility with arduino and providing control.

I will think about adding some options where by more expert users get more control. The only problem is how to keep less expert users from using the options, getting confused and dragging down the forum Smiley
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #9 - Feb 16th, 2016 at 8:37pm
 
Just seen you other post.

Can you please confirm that sonic_range_finder.h is in the project folder?

Confirm that you are using the latest release of visual micro? Tools>extensions and updates will show the latest release.

Thanks
  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #10 - Feb 16th, 2016 at 8:56pm
 
Multiple choice questionnaire in the configuration panel of your software? If the operator can't push enough bulbs together to light the answer to the question they don't get advanced options?

Thanks by the way. So my problem really wasn't my problem. This really is a compatibility issue with Arduino. Is this you keeping your software compatible with the Arduino IDE process or is it something else?

Could you not have a switch that advanced users could throw that says two things...

1) Throwing this switch means you don't get support for this as in this is an edge requirement where most users are hobbyists if you will. Not software or electrical engineers. Which is fair enough for sure. 

I'm sure its just me and being old but it didn't seem clear to me anywhere and I mean "anywhere" that by using the Visual Micro addin (not its fault but to retain compatibility with Arduino) you can't use the standard industry methods in C++ to indicate source directories..

Am I fair in making this statement or is there still hidden in there (or glaring) my rustiness of not being in the business for a few years? 


For a guy that isn't getting paid for what is obviously is a huge project, a labour of love, if you will. How come your "customer service" is better than for products I have paid $100.00's if not thousands for...

Kudo's to you sir...
« Last Edit: Feb 16th, 2016 at 8:59pm by RodW »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #11 - Feb 16th, 2016 at 9:08pm
 
Thanks Smiley The answer is "because I am bonkers" Smiley

Yes visual micro has to try to work within some rules due to the fact that source code is compiled in a temp folder to accommodate building the .ino files and also to allow library references to be resolved. Notice that for arduino shared code libraries you do not #include any paths, just lib header names. This means that vs could not resolve the paths without them being auto discovered.

You are requesting that you manually configure all paths and also that code is auto discovered from those paths. Auto discovered code then needs to be compiled and linked. It's going to get complicated compounded by the fact that arduino's build rules changes every so often.

Generally I think there might be an "advanced option" whereby we simply read the cpp project settings and allow you to specify which folder need to be built into .o files. But then it's more of a make file system which, if you only have one or two projects, you might want to consider.

I am still not clear where your sonic_range_finder.h is located. If outside of the sketch folder why can't it be in your own arduino library? Then the #include paths would automatically be resolved within the arduino framework.
  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #12 - Feb 16th, 2016 at 9:09pm
 
Release (1602.13) is the version I have. Installed on 13'th of this month.

Sonic Range finder (at this point) is still in its own directory under sensors. 

If I understand you correctly I can't use the Visual Studio source and header properties. I plan on moving my directories around a bit (waiting for a confirm from you) so that it will be less typing to do a "relative path" from the project directory to the location of the file. 

Such as;

#include "..\..\Sensor\RangeFinder\OSEPP"

Is the old fart finally on the right track here?
  
Back to top
 
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #13 - Feb 16th, 2016 at 9:18pm
 
LOL - Never considered building my own Arduino library so it falls in the framework. 

I'm assuming you mean to simply house my "library" if you will under the same code tree as the other Arduino files? If so I never thought of that either. Stubborn, Rusty, a combination of both. Who knows... 

Thanks... I'll wait to see what more you have to say.. BTW before the day is up I will be using the PayPal function here. I think my time is worth a bit and I think you may have saved a ton of it with your considerate time. 

I will go and make a donation and hope others do as well to help support your excellent project.

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


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #14 - Feb 16th, 2016 at 9:21pm
 
You can try it but the source code will need to be linked into the project as short cuts. You can create a new folder under the project then add the short cuts to that ("right click folder>add existing>link").

BUT I think it's prone to issue. Why not simply move sensor below the project folder then right click include the code into the project. It's not really built for anything more complex than that.

Looks to me like RangeFinder could possibly be used as an arduino library. Are there any sub folder below "RangeFinder"?

Have you looked at how arduino library/folder/includes work?
  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #15 - Feb 16th, 2016 at 9:29pm
 
I guess I don't want to move it below for code control. How do I use this code in multiple projects? 

Maybe I'm being really slow here, probably am, I have been at this for a long time with little sleep.

If I want to use this same code in many projects what happens if I make a change, discover a bug, etc. How do I know if I have made all the correct changes if I have 23 copies of what should be the code. How do I use this in a version control system? Do I just understand that these files are READONLY and mark them as such. 

Still if a guy had a bunch of projects if a bug was found in a normal system it would trigger a build for all dependencies. If again, I'm correct, doing it this way defeats all of the first mentioned principles..

lol... again, thanks for being so paitent with me...

Cheers,
Rod

P.S 

BTW Only using the Sonic Range Finder as an example. I'm talking more about general long term management and making sure I'm not ever swatting the same bug twice - regardless of the complexity of the sensor I'm programming against.
 

« Last Edit: Feb 16th, 2016 at 9:35pm by RodW »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem with include files
Reply #16 - Feb 16th, 2016 at 9:34pm
 
I think the only missing info realizing what an arduino library is and why they exist.

You can add your code to a new project in visual studio but you need to add all the code as short cuts to your main project and probably add -I includes as I explained earlier.

But it's pushing the boundaries too far if you are not prepared to do those things, even then it's messy.

The safest, most tested and therefore easiest to support method is for you to create arduino libraries from your code. Then each library can be a project and each library can be #included just with filename.h and without need to consider include paths.
  
Back to top
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #17 - Feb 16th, 2016 at 9:46pm
 
LOL. I'm here now...

https://www.arduino.cc/en/Hacking/LibraryTutorial

To see if I was on the same page as you. The writer of this tutorial saying this is weird code referring to;

#ifndef SENSOR_NAME
#define SENSOR_NAME

.. Code here


#endif SENSOR_NAME

How is code like this weird to people working with Arduino's? I mean hooking up a whole bunch of sensors and making a complex machine is hardly a simple task. How are standard form header files so weird? I just don't get it? 

Are people that get into Arduino usually not already into programming and electronics? They have much to learn if not and they have my respect that's for sure. Its a big problem space to wade into... 

Thanks again.

P.S 

Here now

https://www.arduino.cc/en/Reference/APIStyleGuide

Arduino Style Guide for Writing Libraries

This is a style guide to writing library APIs in an Arduino style. Some of these run counter to professional programming practice. We’re aware of that, but it’s what’s made it possible for so many beginners to get started with Arduino easily. 

The underlined made me laugh... I'd say...
« Last Edit: Feb 16th, 2016 at 9:49pm by RodW »  
Back to top
 
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #18 - Feb 16th, 2016 at 10:00pm
 
Thanks for all the time you spent with me today.

I understand now I was fighting against something that was done to simplify the software building process for the Arduino market.

After reading, from your suggestions, it is of course exactly what I will do is add to the Arduino library. I eventually would like to break these dependencies as my skillset increases with this ATMEL controller. If what I'm doing works as well as I would like then a friend, an electronics engineer, and I will probably build our own "Arduino" so my controller can take up less space than a regular Arduino and a custom shield would for example. 

I'll come back in a few days and thank you once more after I have been blissfully coding for a few days and not fighting tools.

You nailed it. I was thinking past Arduino, not realizing that Arduino was a strict architecture for a reason and I would need to work within that structure until I don't need to anymore.

  
Back to top
 
IP Logged
 
RodW
Junior Member
**
Offline


Posts: 12
Joined: Feb 16th, 2016
Re: Problem with include files
Reply #19 - Feb 17th, 2016 at 3:06am
 
Everything working. Interesting that the way I was doing it would have never worked as you pointed out. I can see what we call libraries are not what I call a library really but I understand now and it works flawlessly. Yeah..

Making a whole new set of files exactly following how to make Arduino style libraries and have them in the proper place etc. 

I Still had the same problem... 

Want to know the problem... First hint

I typed save test file as ENTRY_POINT.CPP ENTRY_POINT.H

Figure out what happened to the over tired old dummy? 

I had named the files incorrectly.

ENTRY_POINT.CPP.INO ENTRY_POINT.H.INO... 

Need I say more... Smash forehead and move the #% on.. 

Again thanks... cheers...

« Last Edit: Feb 18th, 2016 at 3:20pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint