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 Is it possible to use link a static class library to an Arduino project? (Read 6290 times)
Scotty
Newbies
*
Offline


Posts: 8
Joined: Oct 7th, 2015
Is it possible to use link a static class library to an Arduino project?
Oct 22nd, 2015 at 11:00am
Print Post  
Hi there,

I have just followed simple steps here to create a very simple static class library in C++ and use it in a very simple console application.
https://msdn.microsoft.com/en-us/library/ms235627.aspx

To make the static class library usable in the console application I needed to:
- Add a Reference in the console application project to the static class library project
- In the console applications project properties I needed to add the path to the static class library project to the following property:
Configuration Properties->C/C++->General->Additional Include Directories

When I went to do this in the Arduino project I found that it had the following property:
Configuration Properties->Linker->General->Additional Include Directories

So I added the path to the static class library there.
I then added a reference in the Arduino project to the static class library.

I then built both the static class library project and the Arduino project and they both built without error.

I then attempted to include the header of a class in the static class library to the Arduino .ino file, but it can't find the file.  Intelliesense doesn't see it and when I compile it says:

TestUsingCPlusPlusStaticLib.ino:3:32: fatal error: SimpleStringGetter.h: No such file or directory
Error compiling


Is it possible to use a static C++ class library in an Arduino project?

Regards,

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


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Is it possible to use link a static class library to an Arduino project?
Reply #1 - Oct 22nd, 2015 at 12:16pm
Print Post  
Normally Arduino can only support code outside of the sketch folder if the code is located in an Arduino library. You can read about arduino libraries on the arduino.cc web site.

Visual Micro pro has the ability for you to include code from other projects using short cuts/links to other code which might help you.

If you come to understand about arduino libraries then ask again and I will give you more info.
  
Back to top
IP Logged
 
Scotty
Newbies
*
Offline


Posts: 8
Joined: Oct 7th, 2015
Re: Is it possible to use link a static class library to an Arduino project?
Reply #2 - Oct 22nd, 2015 at 10:16pm
Print Post  
VM,

Thanks for the response mate.  I have right click on my Arduino project in the solution explorer and selected "Add New Arduino Library" from the context menu, and entered the name "MyTestLib".  But all it did was add the new class header and class an link the header into the .ino file.

Is this what you mean by "arduino libraries"?

I have read both of these:
http://playground.arduino.cc/Code/Library
https://www.arduino.cc/en/Hacking/LibraryTutorial

But it appears that an Arduino Library, is actually just a class in the Arduino project...

I want to be able to write and maintain the code in one place, eg; a separate project to the Arduino project, and then reuse the code in many Arduino projects.

I bought a license for Visual Micro, something I was planning to do for the debugging anyway, so fire away with the details of how to link in classes from an external C++ static library using "short cuts/links"?

Regards,

Scott

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


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Is it possible to use link a static class library to an Arduino project?
Reply #3 - Oct 22nd, 2015 at 11:26pm
Print Post  
Hi the debugger is a different discussion.

You are mistaken about the create lib functionality but the solution explorer can also hide the real picture. It's best to switch the solution explorer to showing the project directory structure instead of the default filtered view. Use one of the small button icons at the top of the explorer to switch view.

The "create library" command created the class in a folder called "[sketchname]\src\_micro-api\libraries\[libname]\src". Notice that the #include that was automatically added to the .ino does not include a path. 

With Arduino, libraries must usually be located in known places such as "mydocuments\ libraries\[libname]\src" and are then "#included" into code without path.

So the create library example creates source code that can be tested and developed and when developed, can easily be deployed to the standard arduino library system and used by other projects or published to the arduino.cc downloadable library manager for the community to use.

Arduino projects normally can only consist of source code in the sketch folder, code in sub folders is not supported. In the arduino world the only way to use a library is to follow the published arduino rules for a library and where it must located so the proper answer to your question is create and use an Arduino compatible library.

Recent versions of visual micro will also compile code from other projects. For example use the standard "Add existing item" feature of Visual Studio to include other source code into the project. Make sure you spot the drop down menu on the "Add existing item" dialog which allows you to optionally selected "As Link". The "Add link" creates a shortcut to the source code.

The intention in the not to distant future is to support debugging in linked code and also in libraries however there are no promises.

It's an idea to play with the arduino ide for a while so that you can understand what Arduino is normally capable of. It might help set your expectation levels Smiley The docs on arduino.cc also explain how arduino libraries work.

So take your pick on which way you want to go Smiley
« Last Edit: Oct 22nd, 2015 at 11:30pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Scotty
Newbies
*
Offline


Posts: 8
Joined: Oct 7th, 2015
Re: Is it possible to use link a static class library to an Arduino project?
Reply #4 - Oct 24th, 2015 at 1:15am
Print Post  
VM,

Thanks for the response.  I will looking forward to debugging support on libraries and linked files.

Is this just an Arduino thing only supporting code in the one folder, or is this and standard across most microprocessors?

Regards,

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


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Is it possible to use link a static class library to an Arduino project?
Reply #5 - Oct 24th, 2015 at 11:31am
Print Post  
Sort of.

Arduino provides a library system which is very popular and in the main avoids the need for complex projects. It's the simplicity of arduino that attracts so many library authors and also 3rd party hardware manufacturers.

The other benefit of arduino style projects is that code remains cross platform so can more easily switch between different boards such as Intel, Atmel, chipKIT etc.

However, all micro-controllers have their own underlying toolchains that allow various levels of complexity and all provide tools that support code in sub folders and almost infinate control over build properties.

But there is no reason not to work towards the best of both worlds as long as support remains fairly easy. Unlike hardware manufacturers there is little profit in software and as such most work is done for free so support has to be a small chunk.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint