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 Developing a library using Visual Micro (Read 3689 times)
vyruz
Junior Member
**
Offline


Posts: 10
Joined: Jan 3rd, 2015
Developing a library using Visual Micro
Dec 25th, 2016 at 10:14am
Print Post  
Hi everyone, merry Christmas!

Happy paying VM user here, thanks again for the great plugin and keep up the good work!

I've been using VM with VS2015 community for about a year now and am very satisfied with it.
Yesterday I wanted to move some code I wrote to a standalone library, in order to be able to use it in other arduino projects I create.
I was happy to find the option 'Arduino Library' under Visual Micro when creating a new project in VS2015. However when I finished my work on the library I was surprised that I couldn't find the library in my other Arduino projects. I did a refresh of the user libraries several times but this did not help.

So I started looking in my libraries folder, and found that the new library I had created with VM had a strange directory structure, my library is called 'NetworkServer':
Code
Select All
\Libraries\NetworkServer\Debug
\Libraries\NetworkServer\NetworkServer
\Libraries\NetworkServer\NetworkServer.sln
\Libraries\NetworkServer\.vs\NetworkServer
\Libraries\NetworkServer\.vs\NetworkServer\v14
\Libraries\NetworkServer\NetworkServer\Debug
\Libraries\NetworkServer\NetworkServer\NetworkServer.ino
\Libraries\NetworkServer\NetworkServer\NetworkServer.vcxproj
\Libraries\NetworkServer\NetworkServer\NetworkServer.vcxproj.filters
\Libraries\NetworkServer\NetworkServer\src
\Libraries\NetworkServer\NetworkServer\__vm
\Libraries\NetworkServer\NetworkServer\Debug\board.buildinfo
\Libraries\NetworkServer\NetworkServer\Debug\core.a
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.bin
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.cpp.d
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.cpp.o
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.elf
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.ino.bin
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.ino.elf
\Libraries\NetworkServer\NetworkServer\Debug\NetworkServer.tlog
\Libraries\NetworkServer\NetworkServer\src\_micro-api
\Libraries\NetworkServer\NetworkServer\src\_micro-api\libraries

\library.properties
\src
\src\NetworkServerLib.cpp
\src\NetworkServerLib.h
\Libraries\NetworkServer\NetworkServer\__vm\.NetworkServer.vsarduino.h
\Libraries\NetworkServer\NetworkServer\__vm\Compile.vmps.xml
\Libraries\NetworkServer\NetworkServer\__vm\Configuration.Debug.vmps.xml
\Libraries\NetworkServer\NetworkServer\__vm\Upload.vmps.xml
 



It seems the actual files I would need in order to use this library in other arduino projects, are located deep down in the \src\ directory.
So I think I missing some step I need to do before I can use this library in other projects, but after some thorough searching on the VM website I'm not able to find what it is. In general there seems to be lack of documentation on how to create arduino libraries.

Or am I looking too far and should I just copy the .h/cpp files to a subfolder of my arduino projects\libraries folder?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12208
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Developing a library using Visual Micro
Reply #1 - Dec 25th, 2016 at 10:38pm
Print Post  
Hi,

Thanks very much for the message.

There is some confusion that I will try to explain.

Arduino has a library system as standard and a user library system where you can put shared libraries downloaded from the internet or created by you. These libraries normally exist in "my documents\arduino\libraries". This is where both arduino and visual micro will look for user libraries unless you have changed your "sketch book" location which defaults to "my documents\arduino"

To use an Arduino library you only ever include the header files without any path qualifier such as #include "libName.h"

Arduino and Visual Micro can automatically resolve library locations in background and users never need to specify library paths. This is easier for users but also means the libraries can always be located even when the sketch book folder is moved. It's an Arduino thing and Visual Micro follows the same rules.

That all makes sense for sharing published libraries between projects but it doesn't make it very easy to develop libraries or have different library versions per project. In this case Visual Micro provides some additional capabilities to assist and it is there capabilities you have used by creating a local project library. The reason why the lib is buried deep is to avoid users from seeing the library sources as part of the project code. As you are now requesting, Arduino libraries can not reference a specific project therefore it would be confusing to consider the part of a project. 

Furthermore Visual Micro is designed so that, even when buried deep, the libraries are #included without paths in the same way that normal shared arduino libraries are #included. This means you can copy (publish) your libraries to the "sketchbook\libraries" folder and share them with other projects. When you add libraries or files to the sketch book\libraries folder, if a project is open that wants to use the new library, click the Rescan button on the Micro Explorer (avoids need to restart the ide before the new library will be detected).

Having local project libraries allows visual micro to more easily detect changes (edits), working outside of the standard Arduino shared and cached library system. Other options are under consideration to help in this area such as allowing multiple projects to shared editable un-cached libraries.

Hopefully this explains some things but please feel free to ask for clarification or discuss further

Finally your arduino sketch book paths will look like this after you copy/publish

This is an arduino library structure using your files. Same as visual micro gives you but in a different place and without the test .ino code and project files. Just the library which must have a .h and folder of the same name

Code
Select All
[sketch book folder]\libraries\NetworkServerLib\library.properties
[sketch book folder]\libraries\NetworkServerLib\src
[sketch book folder]\libraries\NetworkServerLib\src\NetworkServerLib.cpp
[sketch book folder]\libraries\NetworkServerLib\src\NetworkServerLib.h
[sketch book folder]\libraries\NetworkServerLib\src\my_sub_folder\private_stuff.h
 



Other cpp and .h files are allowed in the \src folder or sub folders below \src and they must be #includes with relative paths if in sub folders. #include "my_sub_folder\private_stuff.h"



« Last Edit: Dec 25th, 2016 at 10:46pm by Tim@Visual Micro »  
Back to top
IP Logged
 
vyruz
Junior Member
**
Offline


Posts: 10
Joined: Jan 3rd, 2015
Re: Developing a library using Visual Micro
Reply #2 - Dec 26th, 2016 at 11:08am
Print Post  
Thanks for the explanation, it confirms more or less what I was thinking.
However, it's still not clear to me how I should perform the 'copy/publish' operation you're talking about. 
Is it an option in Visual Studio that I should use?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12208
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Developing a library using Visual Micro
Reply #3 - Dec 26th, 2016 at 9:34pm
Print Post  
It not an option yet. You can open windows explorer and copy/paste manually. An automatic option is on the list for the future.

You can also right click "tabs" or "solution explorer items" then click "Open File Location" so open windows explorer where the source is.

other note

All this assumes you really need a library and don't just want to share some source between multiple projects. In that case you can add create a folder in a more "normal" location that can contain source code and link (add shortcuts) to the source codes into each project. In this case the shortcuts will be treated by the compiler as if they exist in the current project folder.

« Last Edit: Dec 26th, 2016 at 9:37pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint