Adding Libraries to the MikroE IDE
Adding libraries to the MikroElektronika's IDE is probably the strongest reason to use the IDE. We make it so easy to add serious functionality to your IDE that it truly brings meaning to the phrase "we make professional easy". We aim to make your job easier and projects get done faster.
First let's describe the library manager, what it is and how it is used. The project manager can be found, by default on the right side of the IDE.
Library Manager found in the IDE
To include any of the libraries, you simply click on the library you wish to use. That's it. No special placement of files, copying of source, porting, swearing, just clicking.
As of this writing, MikroElektronika has over 200 various click boards that allow easy expansion of your development system but that doesn't stop there. In the last months of 2015, MikroElektronika started an endeavor to also write libraries for each of those boards. No easy task and no it doesn't happen overnight, but progress is happening. This means that for those lucky enough to have a development board, IDE, and click boards you can add the physical board, install the library and be productive faster than anyone else.
Aiding us in the quest to install libraries, we will need the assistance of another piece of software, the Package Manager.
The purpose of the package manager is primarily to install and remove libraries from your IDE, but can be used to package your own libraries and share with loved ones.
Before we can add any libraries we need to find them. Pre-packaged libraries have the .mpkg extension and can be found in multiple locations. The primary repository of libraries for the click board are found at Libstock.com. Others can be found in public repositories on github.com.
Open the newly downloaded package and the contents of the package are described on the left column. Any binaries, source, and header files are contained in the "Libraries" section. Help files and examples are populated with any additional files that might serve as aids to the library.
A grayed out button means the library is not currently installed.
Means that the library is currently installed and can be un-installed by pressing this.
You can run the package manager while the IDE is running or while it is not, but if you do run it while the IDE is currently running, immediate results do not happen. To make the new library appear or disappear from the library manager you need to press the "Refresh Libraries" button in the Library Manager tab:
Not Quite That Easy
Now that you have the library installed it is usable, however there remains one minor step that needs to be observed. Where did the package manager install all these files that were described in the package manager application? The answer: Where did you install your IDE?
In the installation path of your IDE there is a folder: Packages
My installation path is: C:/C4W/Mikroelektronika/mikroC PRO for ARM
Inside the Packages directory you will find all of the packages you have installed, but more importantly is what folders are in there.
Folders found in newly installed packages
Examples - Contains example code for the library
Help - Contains any help files for the library
Uses - Contains any header or source files related to the library
Let's Create
Armed with that knowledge, if we create a new project and include our newly installed library, when we press build we might be faced with a string of errors.
unknown reference to AS4058A_REG1
This is because most often we have definitions that need to be included with the project file. In the example or documentation you will see #include "magneto.h" or something similar. If you add that line to your code:
#include "magneto.h" void main() { // My first click board magneto_init( MAGNETO_SPI, 0, 1 ); }
You'll be facing another error:
cannot open file "magneto.h"
That is because we need to include a path for the compiler to find the header file. That file is located in your package/Uses folder. To add that path to the compiler we need to first click on the Project tab and select "Edit Search Paths".
In the blank section called "Header Files" click the and a dialog box will open. The path we are adding is the package/Uses folder.
Now build the project and all should be well.
If the library doesn't do what you need to, or you are done with the library you can use the package manager to un-install or you can use a shortcut. Alternate click on the library in the Library Manager, and you have a choice to un-install it from there as well.
Enjoy your new found library management powers.