Next: , Previous: PC Compiling, Up: PC Installation



B.3.3.3 Compiling gawk For Dynamic Libraries

To compile gawk with dynamic extension support, uncomment the definitions of DYN_FLAGS, DYN_EXP, DYN_OBJ, and DYN_MAKEXP in the configuration section of the Makefile. There are two definitions for DYN_MAKEXP: pick the one that matches your target.

To build some of the example extension libraries, cd to the extension directory and copy Makefile.pc to Makefile. You can then build using the same two targets. To run the example awk scripts, you'll need to either change the call to the extension function to match the name of the library (for instance, change "./ordchr.so" to "ordchr.dll" or simply "ordchr"), or rename the library to match the call (for instance, rename ordchr.dll to ordchr.so).

If you build gawk.exe with one compiler but want to build an extension library with the other, you need to copy the import library. Visual C uses a library called gawk.lib, while MinGW uses a library called libgawk.a. These files are equivalent and will interoperate if you give them the correct name. The resulting shared libraries are also interoperable.

To create your own extension library, you can use the examples as models, but you're essentially on your own. Post to comp.lang.awk or send electronic mail to ptjm@interlog.com if you have problems getting started. If you need to access functions or variables which are not exported by gawk.exe, add them to gawkw32.def and rebuild. You should also add ATTRIBUTE_EXPORTED to the declaration in awk.h of any variables you add to gawkw32.def.

Note that extension libraries have the name of the awk executable embedded in them at link time, so they will work only with gawk.exe. In particular, they won't work if you rename gawk.exe to awk.exe or if you try to use pgawk.exe. You can perform profiling by temporarily renaming pgawk.exe to gawk.exe. You can resolve this problem by changing the program name in the definition of DYN_MAKEXP for your compiler.

On Windows32, libraries are sought first in the current directory, then in the directory containing gawk.exe, and finally through the PATH environment variable.