Other useful tip:
You can create a source file with the declaration of a single data
element. This is useful for instance for buffers.
You may have a function that needs a buffer and the library comes
already with a definition of a standard one so the library user doesn't
need to worry about it, but if he/she needs a different one (larger, for
instance) he/she can declare a new one in his/her own code.
Functions and data declared in the user's code have precedence over the
ones defined in the library, so the user just needs to supply a new one.
If the library's standard definition for the data is implemented in the
same source file with other data or functions, the linker will give a
"duplicated definition" error.
Don't forget that you must create a way to tell the library function
that the buffer has now a different size. You could define a variable
like "const int BufferLength = sizeof Buffer;" in the same file with the
buffer definition, and your functions must user that variable to access
the buffer length. When the user creates a new definition, he/she must
created the same variable also.
Isaac
Em 2/5/2012 10:44, Isaac Marino Bavaresco escreveu:
{Quote hidden}> Em 30/4/2012 20:58, kris duff escreveu:
>> Hello,
>>
>> I want to begin to put some of my "common/utils" code in one or more library so it would be easier for me to test my code, reuse and track versions.. I did not found any great resources to learn general guidelines for microchip compiler.
>>
>> As I said in the subject line, I will use MCC18.
>>
>> So, is there any great website, application note, book ... that could be helpfull for me ?
>>
>> Thank you a lot!
>>
>> Kris
>
> It is not hard, follow these steps:
>
> 1) Menu "Project" -> Option "Build Options..." -> Option "Project" ->
> Tab "MPASM/C17/C18" -> Radio button "Build library target (invoke MPLIB)"
>
> 2) If your library is not specific for a particular device, check the
> check-box "Build generic library".
>
> 3) Write each one of your library's functions in a separate source file,
> unless some of them are always linked together, then you can put these
> in the same source file.
>
> 4) If there are some functions or data that should not be seen by the
> linker, make them "static". Please note that only functions in the same
> source file can see them, then it is pointless to have only "static"
> functions and data in a source file. At least one function in the same
> file must be global. These global functions will be accessible by the
> linker and they will access the "static" data and functions.
>
> 5) Create header files with the declaration of your library's data and
> functions and #include them in the source files that implement them.
> These same header files will be #included in your application source
> files also. This will ensure that the compiler will generate the correct
> code to call your library's functions. You may create several header
> files to group declarations in a logical manner.
>
>
> There are a lot of other small details, but you will figure it out in
> the process.
>
>
> Best regards,
>
> Isaac
>