Loading Shared Libraries (The GNU Awk User’s Guide)
Next: Obsolete, Previous: Include Files, Up: Invoking Gawk [Contents][Index]
2.8 Loading Dynamic Extensions into Your Program
This section describes a feature that is specific to gawk
.
The @load
keyword can be used to read external awk
extensions (stored as system 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 extension. Using @load
is completely equivalent to using the -l
command-line option.
If the extension is not initially found in AWKLIBPATH
, another search is conducted after appending the platform’s default shared library suffix to the file name. 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 an extension.
Writing Extensions for gawk, describes how to write extensions (in C or C++) that can be loaded with either @load
or the -l
option. It also describes the ordchr
extension.