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.

Note:

Linking is supported for backward compatibility, it is recommended that you use IMPORT FGL instead.

Library linking is done with the fgllink tool, or with the fglrun tool by using the -l option. The fgllink tool is a wrapper script for fglrun -l .

The following lines show a link procedure to create a library in a UNIX™ shell session:
$ 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.

Important:

The 42x library file does not contain the 42m p-code. When deploying your application, you must provide all compiled 42m modules.

When creating a 42x library, all functions must be uniquely defined; otherwise, error -6203 will be returned by the linker.

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

It is possible to create a library by referencing other 42x library files in the link command, as long as 42m modules can be found:
$ 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

If you are using C-Extensions, you may need to use the -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