Make and use my own library

General discussion on mikroC.
Post Reply
Author
Message
PeteNZ
Posts: 7
Joined: 26 Aug 2005 05:16
Location: Wellington N.Z.

Make and use my own library

#1 Post by PeteNZ » 07 Nov 2006 08:41

Ok, I give up -- how do I make and use my own library. Is there a guide for doing this? I couldn't find anything much in the manual or compiler help.

I have a pretty good task dispatcher written. I used to just copy the source file into any project that needed the dispatcher, but lately decided to get more sophisticated and make a library out of it. There seems to be a demand for multi-tasking systems, and even though this is a long way from a full RTOS I find it very useful. I am sure others will too, so I may release it for free use once I get this library stuff sorted out.

I can compile it (V6.2 compiler) seperate from any project, but only if I have a main(), which may or may not be an issue.

Anyway, when I add the .mcl file to another project the compiler doesn't know about the functions within the library. Do they have to be declared as public or something? I'd like to hide the internal procedures too (private?). I tried using those keywords without success.

-- Pete

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

Re: Make and use my own library

#2 Post by rajkovic » 07 Nov 2006 09:49

PeteNZ wrote:Ok, I give up -- how do I make and use my own library. Is there a guide for doing this? I couldn't find anything much in the manual or compiler help.

I have a pretty good task dispatcher written. I used to just copy the source file into any project that needed the dispatcher, but lately decided to get more sophisticated and make a library out of it. There seems to be a demand for multi-tasking systems, and even though this is a long way from a full RTOS I find it very useful. I am sure others will too, so I may release it for free use once I get this library stuff sorted out.

I can compile it (V6.2 compiler) seperate from any project, but only if I have a main(), which may or may not be an issue.

Anyway, when I add the .mcl file to another project the compiler doesn't know about the functions within the library. Do they have to be declared as public or something? I'd like to hide the internal procedures too (private?). I tried using those keywords without success.

-- Pete

Creating library files and their use:

1. make c file that contains all your library functions,
it must not contain definition of main,
also take care that name of your library file is unique
and will not conflict with default libraries that are located
in corresponding uses folder
2. add your c file to any project and build project
you will get mcl file.
Now we have our library but how to use it.

There are 2 ways to achive this:

1. add mcl file to any project as library file.
in order to make any other file in project
see declaration of function in this file
you must
-make header file *.h with all protypes of
functions that are pubilc and should be visible
-include this header file where you need this
library functions.

2. you may consider to make this library loaded by default
then you do not have to make header file
and will see all functions on CTRL+Space
- mcl file must be copied to uses/p1x appropriate folder
- for any PIC that should use this library
find mlk file (defs folder) and add pragama
#pragma SetLib(library_name_without_exstension)
in order to make compiler aware of this change
you must change PIC and revert again
to selected (to make compiler load libraries again)
or simply restart compiler
Downside of this way is that compiler will always load all mcl (library) files set in the mentiond mlk file in order to give function prototypes on CTRL+space. Although it does not affect the size of HEX file generated if you do not use those library functions, it may slow down compilation proccess if a lot of libraries are added this way as default.
First way is recommended if the library is used with a certain projects and the second way is recommended if the library is general purpose one and used often with a certain mcu.

cny61
Posts: 2
Joined: 03 Apr 2010 19:20

Re: Make and use my own library

#3 Post by cny61 » 05 Mar 2012 17:13

I tried to use same .mcl file MikroC and MikroP. But i couldnt.

Can i use same .mcl file in MikroC and MikroB and MikroP ? Is it possible ?

Thank You All ...

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Make and use my own library

#4 Post by janko.kaljevic » 06 Mar 2012 10:46

Hello,

I believe that I have answered you here:
http://www.mikroe.com/forum/viewtopic.php?f=93&t=47231

Best regards.

Post Reply

Return to “mikroC General”