Previous: Installing Libraries, Up: Working With Libraries   [Contents]


5.4.2 Using Libraries

To use the functions and classes from a compiled library, you must:

The compiler must know that you want to make use a compiler library. You can accomplish this in two ways. The first is to specify the library on the command line with the -u option.

This example assumes a library named mylib was built and installed to the library path, and the main.php program wishes to use functions from the library.

$ pcc -u mylib main.php

Alternatively, if you want to include mylib as one of the default libraries used during all builds, you can add it to default-commandline-lib in the configuration file.

Finally, the project that wants to make use of a library must still include or require the source file from the library that it wants to use.

For example, if the mylib example library above included a source file foobar.php that contains function library_function that main.php wishes to use, it must call:

<?

// include from compiled library
include('foobar.php');

// now we can run a function from the compiled library mylib 
library_function();

?>