Linking libraries
Describes how to link .42m modules together to build a .42x library file.
Grouping .42m modules in .42x libraries
Compiled .42m modules can be grouped in libraries using the fgllink linker. The library file gets the .42x extension.
The linker can be used to create .42x libraries or .42r
program files. If none of the modules provided to the linker defines the MAIN
block, the linker creates a library file; if a MAIN
block is present, the linker
creates a program file. Make sure to use the correct file extension.
IMPORT FGL
instead.Library linking is done with the fglrun tool by using
the -l
option. The fgllink tool can be used for convenience, it
is a simple script calling fglrun -l
.
$ fglcomp fileutils.4gl
$ fglcomp userutils.4gl
$ fgllink -o libutils.42x fileutils.42m userutils.42m
When you create a library, all functions of the 42m modules used in the link command are registered in the 42x file.
When creating a 42x library, all functions must be uniquely defined; otherwise, error -6203 will be returned by the linker.
Providing the files to link in an arguments file
The fglrun/fgllink linker supports the
@argfile
argument, to provide a file that contains the list of
.42m modules and .42x libraries to be used for the link.
This can be used when it is not possible to pass all files in the command line.
Only link files must be specified in the arguments file. Linker options must be provided in the command line.
The argument file must contain one file per line:
$ cat myfiles.txt
module1.42m
module2.42m
$ fgllink -o lib1.42x @myfiles.txt
Using libraries when linking programs
The 42x libraries are typically used to link the final 42r programs:
$ fglcomp mymain.4gl
$ fgllink -o myprog.42r mymain.42m libutils.42x
The 42r programs must be re-linked, if the content of the 42x libraries changes.
In this example, if a function of the userutils.4gl source file was removed, you must recompile userutils.4gl, re-link the libutils.42x library and re-link the myprog.42r program.
Linking libraries with other libraries
$ fglcomp module_1.4gl
$ fglcomp module_2.4gl
$ fgllink -o lib_A.42x module_1.42m
$ fgllink -o lib_B.42x module_2.42m lib_A.42x
$ fgllink -o myprog.42r lib_B.42x
-- will hold functions of module_1 and module_2.
P-Code module find path FGLLDPATH
If you do not specify an absolute path for a file, the linker searches by default for 42m modules and 42x libraries in the current directory.
If the 42m modules are not in the current directory, you can specify the 42m module search path with the FGLLDPATH environment variable.
Linking libraries when using C Extensions
-e
option to specify the list of extension modules, if the
IMPORT
keyword is not used:
$ fgllink -e extlib,extlib2,extlib3 -o libutils.42x fileutils.42m userutils.42m