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
Normal Topic Source Defines Affect Libraries project option does not seem to work. (Read 2605 times)
Cynthia MacLeod
Newbies
*
Offline


Posts: 6
Joined: May 22nd, 2018
Source Defines Affect Libraries project option does not seem to work.
Aug 31st, 2018 at 4:32pm
Print Post  
I have tried a few combinations and cannot get this option to work as described.

I have tried a shared project setup as a library, and the template with a library in the _micro-api folder.

My simple test was to add
#ifdef SketchDefine
#pragma message("SketchDefine Found")
#else
#pragma message("SketchDefine Missing")
#endif
to Library1.h

Then compiling the .ino file with no project defines results in Missing twice.
If you set the define in the project properties under Micro General (Project Global) you get Found twice.
If you set the option for Source Defines affect Libraries and add #define SketchDefine to the .ino file, you get Missing when is compiles Library1.cpp as a library and Found when compiling the .ino file.

Ideally I want to add #include "defines.h" to the .ino and put the #define in that file in the project so it is easily read and edited rather than having it embedded in the .vcxproj xml file.

Am I misunderstanding how this is supposed to work, or is there an easier way of dealing with this?

For reference I am using the latest release build of VM and VS.

VM 1808.30.4
VS 15.8.2
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Source Defines Affect Libraries project option does not seem to work.
Reply #1 - Aug 31st, 2018 at 8:14pm
Print Post  
Hi,

1)

If you ensure you have the "pragma once" command at the top of your header files I hope you only see one mesage

2)

To answer the question I suggest asking on the arduino.cc web site. I wouldn't mention your lib is in _micro-api because that will confuse. It's just a standard arduino library.

3)

A tip for less confusion is to put your libraries in a folder outside of the project folder. Maybe a sibling folder of the project, both below the solution.

Putting libs below the _micro-api\librares folder and also making them shared projects kind of defeats the object of shared lib projects because files under the _micro-api can be directly included into the project via the solution explorer but isn't very compatible with the arduino ide.

- Solution
     -  MyLibs
        -  Lib1
     -  MyProject1

Hope this helps a bit.

« Last Edit: Aug 31st, 2018 at 8:14pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Cynthia MacLeod
Newbies
*
Offline


Posts: 6
Joined: May 22nd, 2018
Re: Source Defines Affect Libraries project option does not seem to work.
Reply #2 - Sep 3rd, 2018 at 1:47pm
Print Post  
I have tried it with a clean project from the template of "Arduino Project With Local Library", hence the _micro-api folder, but also with separate shared projects for the library as you suggest (my main projects where I found the issue were already setup like that anyway).

I do have pragma once, but because it is a library it shows twice; once when compiling Library1.cpp including Library1.h to create Library1.cpp.o and once when compiling Sketch.ino to Sketch.cpp.o as it is needed in each case.

The problem is that if I use the project properties to set Defines as SketchDefine is shows as found in both cases.
If I use a #define in the .ino file or a .h file included in the main project and select Source Defines affect Libraries - the source defines do not affect the libraries and I get Missing when compiling the Library and Found when compiling the main project.
If I have optional code and function declarations in the library, then when compiling the sketch it includes them, but when linking it fails as when it compiled the library it did not include them.
I was under the impression the option for source defines affecting libraries and affecting core was a VisualMicro thing, not an Arduino thing hence asking here.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Source Defines Affect Libraries project option does not seem to work.
Reply #3 - Sep 3rd, 2018 at 4:29pm
Print Post  
Hi,

Source defines affect libraries is related to cache/build and unrelated to passing defines to the library compiler. I would leave that option at the default setting and then ignore it.

In the arduino world project defines do not affect libraries which is why visual micro has the additional project property option.

Maybe a work around is to create a library called "MyDefinesLib" (or some other name) that includes the defines in MyDefinesLib.h and then reference the lib header <MyDefinesLib.h> in all libraries and the project.

Does that work?





  
Back to top
IP Logged
 
Cynthia MacLeod
Newbies
*
Offline


Posts: 6
Joined: May 22nd, 2018
Re: Source Defines Affect Libraries project option does not seem to work.
Reply #4 - Sep 3rd, 2018 at 9:31pm
Print Post  
Hmmm. The definition and explanation in the documentation page are rather unclear then.
If the defines in the project source do not get passed to the libraries, why do you need to invalidate/rebuild them if the defines change?
Anyway - I am using project properties under Micro General (Project Global) -> Defines and it works.
However I find that with 3 (or more) top level projects in my solution, along with multiple shared libraries, that when you update the defines in the UI, it often does not update the project or updates the defines in the wrong project.
This would be much better as a popup window with a grid of defines with optional values rather than the ; delimited list it currently is.
It is also not entirely clear where this is stored in the project file. I was expecting it to be the ItemGroup for Preprocessor Definitions so that intellisense would work the same as the build but that doesn't appear to be the case.
Is there detailed references for the files generated / in use and what settings are stored where? I can't find much in the documentation part of the site.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Source Defines Affect Libraries project option does not seem to work.
Reply #5 - Sep 9th, 2018 at 1:29pm
Print Post  
Quote:
Hmmm. The definition and explanation in the documentation page are rather unclear then.
If the defines in the project source do not get passed to the libraries, why do you need to invalidate/rebuild them if the defines change?

Yes it's a tricky area. I think that feature was added long ago for the ArduPilot drone project that had a modified ide. Probably needs to be removed because normal arduino doesn't work that way.

Quote:
However I find that with 3 (or more) top level projects in my solution, along with multiple shared libraries, that when you update the defines in the UI, it often does not update the project or updates the defines in the wrong project.


I can look at this if needed but it is an area that can be confusing due to the way VS works. There is a mini button above the solution explorer that auto synchronizes the solution explorer with the active code that is being edited. If that option is off (which is how I prefer to work) then the active code and the solution explorer are two different selections.

You might think that clicking the solution explorer should always be the selected project or vica versa. However if you look at the Project, Build and Debug menu you will see which project VS thinks is active. It's not always the one you would think should be active. 

Then when you press F5 to upload which project is uploaded? The one being edited or the one selected in the solution explorer.

Maybe the bug is that the project properties are not refreshing correctly.

Which version of VS are you using exactly? 

Quote:
This would be much better as a popup window with a grid of defines with optional values rather than the ; delimited list it currently is.


Yes its on the list. Time is short and Microsoft/Arduino in VsCode with the linux, mac and some windows users are taking all the blogs and pr so i'm spending more of the available time considering marketing at the moment. I don't think windows/vs users like blogging or tweeting much Smiley

Quote:
It is also not entirely clear where this is stored in the project file. I was expecting it to be the ItemGroup for Preprocessor Definitions so that intellisense would work the same as the build but that doesn't appear to be the case.


There are defines required to make vs intellisense work which would interfere with the build (because the real compiler sets what it wants accurately). Therefore the standard vs project defines need to be automatically updated with "stuff" that makes intellisense work.

Global defines are stored in a section of the project or .user file. We use global project properties but you have to use the project properties for now. If you put it at the bottom of the screen it can take the full length so is easier to work with. 

Defines for the configuration are stored in the xml files in the \_vm folder. You will see the file names contain the project name and the configuration name. However because vs sends messages to show the project properties many times the files are cached. There is only one cache for all projects in a solution, so clicking between two top level projects should invalidate it. 

Quote:
Is there detailed references for the files generated / in use and what settings are stored where? I can't find much in the documentation part of the site.


The site is in the process of being re-done with a new better documentation/wiki area. Will add to that but there are only the config specific files I have mentioned and properties in the proj.
« Last Edit: Sep 9th, 2018 at 1:30pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint