Language basics / Programs |
Importing external modules in the current module.
The IMPORT instruction can be used to declare the usage of an external module. All (public) symbols of the external module can be referenced in the current module.
The IMPORT instruction must be the first instruction in the current module. If you specify this instruction after DEFINE, CONSTANT or GLOBALS, fglcomp will report a syntax error.
The IMPORT instruction can import a compiled 4gl module, a Java™ class or a C extension library:
The name specified after the IMPORT FGL or IMPORT JAVA instruction is case-sensitive: Program module (.4gl) or Java class must exactly match the file name. However, for backward compatibility, C extension library names are converted to lowercase by the compiler (therefore, we recommend you to use lowercase file names for C extensions). A character case mismatch will be detected on UNIX™ platforms, but not on Windows™ where the file system is not case-sensitive. Regarding the usage of imported symbols in the rest of the code (i.e. not the IMPORT instruction): C extensions and Genero symbols are case-insensitive, while Java symbols are case-sensitive.
Using IMPORT libname instructs the compiler and runtime system to use the libname C extension for the current module. This C extension must exist as a shared library (.DLL or .so) and be loadable (environment variables must be set properly). C extension modules used with the IMPORT instruction do not have to be linked to fglrun: The runtime system loads dependent C extension modules dynamically.
The name of the module specified after the IMPORT keyword is converted to lowercase by the compiler. Therefore it is recommended to use lowercase file names only.
The FGLLDPATH environment variable specifies the directories to search for the C extension modules. You may also have to setup the system environment properly (i.e. PATH on Windows and LD_LIBRARY_PATH on UNIX) if the C extension library depends from other libraries.
By default, the runtime system tries to load a C extension module with the name userextension, if it exists. This simplifies the migration of existing C extensions; you just need to create a shared library named userextension.so (or userextension.dll on Windows), and copy the file to one of the directories defined in FGLLDPATH.