Next: , Previous: , Up: Invoking Gawk   [Contents][Index]

2.8 Loading Shared Libraries Into Your Program

This section describes a feature that is specific to gawk.

The ‘@load’ keyword can be used to read external awk shared libraries. This allows you to link in compiled code that may offer superior performance and/or give you access to extended capabilities not supported by the awk language. The AWKLIBPATH variable is used to search for the shared library. Using ‘@load’ is completely equivalent to using the -l command-line option.

If the shared library is not initially found in AWKLIBPATH, another search is conducted after appending the platform’s default shared library suffix to the filename. For example, on GNU/Linux systems, the suffix ‘.so’ is used.

$ gawk '@load "ordchr"; BEGIN {print chr(65)}'
-| A

This is equivalent to the following example:

$ gawk -lordchr 'BEGIN {print chr(65)}'
-| A

For command-line usage, the -l option is more convenient, but ‘@load’ is useful for embedding inside an awk source file that requires access to a shared library.

Dynamic Extensions, describes how to write extensions (in C or C++) that can be loaded with either ‘@load’ or the -l option.