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 What happens under water when adding a library? (Read 4166 times)
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
What happens under water when adding a library?
May 16th, 2017 at 9:08pm
Print Post  
Can you please enlighten me in my 100th attempt to understand using libraries with the VisualMicro extension ..

What happens when you add a library to a project when the "create project" setting is off and when it is on?
If I add a library to my project with the settings off, and then remove the include from my main .ino file .. the project still seems to find the library, so it looks like there are more changes made then just the #include

If I look in the build folder, I see several duplicate .o files  (that the linker is of course complaining about) 
Mostly one in the main folder and one in a subfolder for the library. Which setting / reference / inlcuded project setting is causing the compiled objects in the library folder and how are they compiled in the main folder?
« Last Edit: May 16th, 2017 at 9:12pm by Bas »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: What happens under water when adding a library?
Reply #1 - May 16th, 2017 at 9:25pm
Print Post  
Hi,

Quote:
remove the include from my main .ino file the project still seems to find the library, so it looks like there are more changes made then just the #include


I think you are just talking about intellisense, the compile fails? Except for the following conditions.

#includes are auto discovered in both .ino and .cpp sources. Also other libraries are discovered from the .cpp sources of  discovered libraries. 

When you have the "create lib project" setting ON, a new project is added to solution with the library sources. Doing this will probably allow Visual studio to show intellisense for the library even if it is not being used in your code.

You are then instructed to use the "References" setting of the master project to add a reference to the newly created library project. Doing this causes visual micro to always attempt to compile the library when the project compiles regardless of discovered #includes. Adding a reference also allows visual studio to show the correct intellisense when editing the library project code.

If the code #includes a library then the library will always be compiled if the library exists in an official Arduino (regardless of visual studio solution configuration, this is also how Arduino IDE works)


other info

Build>Rebuild always gives clean compile removing all old temp files which when deleting sources can cause confusion. Doesn't seem to apply to your questions but worth a mention.
  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: What happens under water when adding a library?
Reply #2 - May 17th, 2017 at 6:33am
Print Post  
My main interest here is whats happening during compilation, not intellisense.

So if I understand correctly ...
  • Includes are discovered automatically, and this goes on recursively. 
  • NOT adding a reference will not have any effect on the compilation process in terms of finding sources files to compile (it will effect intellisense)
  • Adding a library as a shared project does not have any effect on the compilation process 



That leaves the following questions:
  • If one file of a library is included in my .ino will this cause the compilation of all files in the same library folder?
  • When does the compilation of a sourcefile from a library results in an .o file in the main build-folder and when does it result in the .o file being placed in a subfolder for the library? (The results in my build folder show nearly every library file being placed in the main build folder AND in the subfolder per library. This is of course causing all kinds of "duplicates" errors during linking)
  • What locations are used in the auto-discovery process when I have No IDE selected?


Sorry to be asking so many questions on this .. but I'm really trying to understand this process .

EDIT:
After compiling and receiving lots of "already defined" messages, I've found the file "include_path.txt" and it contains something that looks like being the cause of this:

Quote:
arduino
ts\mega
D:\Development\CSense\C-Sense2.0\source\libraries\Adafruit_INA219
D:\Development\CSense\C-Sense2.0\source\libraries\Adafruit-BMP085
D:\Development\CSense\C-Sense2.0\source\libraries\DHT-sensor-library
D:\Development\CSense\C-Sense2.0\source\libraries\MPU6050-jarzebski
D:\Development\CSense\C-Sense2.0\source\libraries\MemoryFree
D:\Development\CSense\C-Sense2.0\source\libraries\StandardCplusplus
D:\Development\CSense\C-Sense2.0\source\libraries\Timer
D:\Development\CSense\C-Sense2.0\source\libraries\SoftwareSerial\src
D:\Development\CSense\C-Sense2.0\source\libraries\ic2devlib
D:\Development\CSense\C-Sense2.0\source\libraries\Wire\src
D:\Development\CSense\C-Sense2.0\source\libraries\DS3231
D:\Development\CSense\C-Sense2.0\source\libraries\SD
D:\Development\CSense\C-Sense2.0\source\libraries\SPI
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\m3isb2kz.cfl\Micro Platforms\default\debuggers\VM_DBG
D:\Development\CSense\C-Sense2.0\source\libraries\EEPROMEx
D:\Development\CSense\C-Sense2.0\source\libraries\SenseNextionFramework\src
D:\Development\CSense\C-Sense2.0\source\libraries\SenseFramework\src
D:\Development\CSense\C-Sense2.0\source\libraries\Nextion
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\m3isb2kz.cfl\Micro Platforms\visualmicro\ide\libraries
ies
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\m3isb2kz.cfl\Micro Platforms\default\debuggers
D:\Development\CSense\C-Sense2.0\source\libraries


The last line includes all libraries again, after they are specifically added earlier in the file.
Is this correct??


« Last Edit: May 17th, 2017 at 5:52pm by Bas »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: What happens under water when adding a library?
Reply #3 - May 19th, 2017 at 2:43pm
Print Post  
I think the confusion is what I explained before.

You have added a reference to a shared project that you expect to be treated as a library. However the library does not contain a library.properties text file. Therefore visual micro is treating is a project code and attempting to compile as project code and not library. In this case you will see a .o in the project code folder and not the lib folder.

Quote:
Adding a library as a shared project does not have any effect on the compilation process


Yes it does. It causes the library to be auto discovered even if there is no #include.



  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: What happens under water when adding a library?
Reply #4 - May 22nd, 2017 at 7:49pm
Print Post  
Ok .. something else I learned tonight .... 
If the libraries.properties is in the main folder of a library, but the .vxitems file is in the src subfolder .. then it will not be seen as an Arduino library when added to a solution as shared project

And that after adding a shared project to the references of a project, the library folder is added to the projects "AdditionalIncludeDirectories" .. but these are not removed is you remove the reference from the main project
« Last Edit: May 22nd, 2017 at 8:14pm by Bas »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: What happens under water when adding a library?
Reply #5 - May 22nd, 2017 at 9:41pm
Print Post  
Hi,

Interesting. yes the vcxitems is expect to be in the library root, visual micro can't know it is in a library unless it can establish what the root is. In a shared project the "special arduino libraries" folder(s) are not factored in at all. 

The AdditionalIncludeDirectories is only for intellisense. It should include the library path if visual micro believes the library has to be compiled. I will check on what happens when you remove a shared reference, vs has a few caching issues in this area but maybe it's a visual micro issue.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint