Contents


Compiling programs


Purpose:

The fesqlc tool compiles and links C programs that contain Genero ESQL/C (FESQLC) source code files, creating an executable C program.  An FESQLC source file must be preprocessed before a C compiler can compile it.  By default, your FESQLC source files are passed to the FESQLC preprocessor, and then to the C compiler. You can choose to preprocess only.

Syntax:

fesqlc [options] source.ec [othersrc.ec ...] 
        [othersrc.c ...] [otherobj.o ...] [otherlib.a ...] 

Notes:

  1. options are described below.
  2. The FESQLC source code files must have the extension .ec.
  3. othersrc.c are C source files to be linked.
  4. otherobj.o are C object files to be linked.
  5. otherlib.a  are C static libraries to be linked.  

Options:

 Option  Description
 -V Display version information
 -h Display this help
 -v Verbose mode (display information messages)
 -e Preprocess only
 -G No line numbers (for debugging purposes)
 -c Compile to object file
 -o name Output file specification
 -d name Database interface type
 -dl Display supported database interfaces
 -ED name Define an preprocessor macro for FESQLC macros
 -EU name   Un-define a preprocessor macro for FESQLC macros
 -D name Define a preprocessor macro for C macros
 -U name Un-define a preprocessor macro for C macros
 -I path Specify a path for C and FESQLC includes
 -W option Warnings: option can be one of:
all: enable all warnings
 -cpf "flag .." C compiler flags
 -lkf "flag .." Linker flags


Usage:

Options can be used for preprocessing only, or for preprocessing/compiling/linking.  Options are global and affect all files.

The -V (display version information) and -h (display help) options do not require source file names:

fesqlc -V
fesqlc -h
The -e option suppresses compiling and linking of the source file.  The file will be preprocessed by FESQLC and output as a C source code file (filename.c).
fesqlc -e mysource.ec

The -c option preprocesses the source file, and then compiles it to object code (filename.o). By default the 'cc' compiler is used on Unix. You can modify the C compiler by setting the FGLCC environment variable. On Windows, the default is 'cl.exe'.

fesqlc -c mysource.ec

Use the -o option to specify the output file name for the executable file that is the result of preprocessing, compiling and linking. Link is performed by a call to the fglmkrun tool, to link with FGL runtime system libraries and database driver.

fesqlc -o myprog file1.ec

The -d option allows you to specify the database interface type. Use the -dl option to list the valid database interface types:

fesqlc -dl
fesqlc -d ora920 file1.ec

Use the option -ED name to define a global FESQLC macro. This has the same effect as an FESQLC define preprocessor directive at the top of your program.

fesqlc -ED CHECKED file2.ec

Use the option -EU name to undefine an FESQLC macro, removing it globally from the entire program.

fesqlc -EU CHECKED file2.ec

Use the -D and -U options only to define and un-define C macros for your program.

Example:

fesqlc -o prog1 -ED DEBUG -I ./include -d ora920 \
        file1.ec file2.ec file3.ec

In this example the executable output file will be named prog1, a global macro named DEBUG is defined, the include path is specified as ./include, and the database type is Oracle 9.20.  Files to be processed include file1.ec, file2.ec and file3.ec


Linking ESQL/C Extensions to a Genero runner


This sections describes how to create a Genero runner with C Extensions written in ESQL/C.

To create the runner, you must:

  1. Include the fglExt.h file to the .ec files implementing C functions called from Genero BDL.
       #include <f2c/fglExt.h>
  2. Compile all the .ec sources to object files with fesqlc, by using the -c option.
  3. Create the extension interface as described in C Extensions.
  4. Link the runner by specifying the database interface type, the extension interface file, the additional object files and the libfesqlc.a library:
       -d <database-interface-type>
       -ext myext.c
       -aob "mod1.o mod2.o ..."
       -alb $FGLDIR/lib/libfesqlc.a

Use the -v option of fglmkrun if you experience problems during the link.

Example:

This example uses three sources:

-- The mod1.ec source --------------------------------------
#include <f2c/fglExt.h>
exec sql include sqlca;

int insert_row(int c)
{
   exec sql insert into dbit2 values (1, 'aaaa', 'bbbbb');
   return 0;
}

-- The myext.c source --------------------------------------

#include "f2c/fglExt.h"

int insert_row(int);

UsrData usrData[]={
  { 0, 0 }
};

UsrFunction usrFunctions[]={
  { "insert_row", insert_row, 0, 0 },
  { 0, 0, 0, 0 }
};

-- The prog.4gl source -------------------------------------

MAIN
   DATABASE stores
   CALL insert_row()
END MAIN

First, we link the extension module. This creates the object file (mod1.o):

fesqlc -c mod1.ec

Then, we link the runner (with Oracle database interface in this case):

fglmkrun -o runora -d ora920 \
  -ext myext.c \
  -aob mod1.o \
  -alb $FGLDIR/lib/libfesqlc.a