Creating and Using Libraries

With Basic18, you can create precompiled libraries of frequently used functions and procedures.  Once created, you simply load the library with the Option LoadLibrary command, and use the procedures as you would any other procedure in your source code.  Any unused procedures, and their local variables, are not included in the final program.

To create a library, simply add the Option Library command to your source code.

Notes concerning creating libraries:

  1. Global variables and constants are not stored in the library.
  2.  Do not create a main procedure.

  3. The processor should be set to NONE in the project before compiling to a library

Creating a library example:

Option library test1.lib   ' Create a library named test1.lib in the current directory
 
Sub proc1()
  dim a as ubyte
  for a=0 to 9
    PORTB=a
  next a
End Sub
 

Using a library example:

Option loadlibrary "test1.lib"  ' test1.lib contains the procedure  proc1()
 
Sub main()
  call proc1()   ' proc1() has been included from test1.lib
End Sub