Was this helpful?
How Embedded SQL Programs are Linked
Embedded SQL programs require procedures from an Ingres library or libraries depending on your operating system as described below.
UNIX:
The Ingres library "libingres.a" must be included in your compile (f77) or link (ld) command after all user modules. The following example demonstrates how to compile and link an Embedded SQL program called "dbentry" that has passed through the preprocessor:
f77 -o dbentry dbentry.f \
     $II_SYSTEM/ingres/lib/libingres.a\
     -lm\
     -lc
Note that you must include the math library (the "m" argument to the -l flag).
Ingres shared libraries are available on some UNIX platforms. To link with these shared libraries replace "libingres.a" in your link command with:
-L $II_SYSTEM/ingres/lib -linterp.1 -lframe.1 -lq.1 \
     -lcompat.1
To verify if your release supports shared libraries check for the existence of any of these four shared libraries in the $II_SYSTEM/ingres/lib directory. For example:
ls -l $II_SYSTEM/ingres/lib/libq.1.*  
VMS:
Embedded SQL programs require procedures from several VMS shared libraries. When you have preprocessed and compiled an Embedded SQL program, you can link it. Assuming the object file for your program is called "dbentry," use the following link command:
link dbentry.obj,-
 ii_system:[ingres.files]esql.opt/opt  
Windows:
The Ingres library libingres.lib must be included in your compile (df) or link (link) command after all user modules. The following example demonstrates how to compile and link an Embedded SQL program called "dbentry" that has passed through the preprocessor:
df /name:as_is /iface:nomixed_str_len_arg /iface:cref dbentry.for \
     %II_SYSTEM%\ingres\lib\libingres.lib \
     /link /nodefaultlib  
Link Precompiled Forms
The Forms-based Application Development Tools User Guide and the Fortran Variables and Data Types discuss how to declare a precompiled form to the FRS. To use such a form in your program, you must also follow the steps described below, depending on your operating system.
UNIX:
To link a precompiled form
1. In VIFRED, select a menu item to compile a form. VIFRED then creates a C language source file in your directory that contains a description of the form. Select a name for the file.
2. Before compiling and linking this file with your Embedded SQL program, make the form name, or formid, contained therein consistent with the way Fortran stores external symbols.
When you compile the Fortran source file generated from your Embedded SQL program, the Fortran compiler appends an underscore to all external symbols. Some Fortran compilers also truncate names to six characters before appending the underscore. Because the formid is an external symbol, it too has an underscore appended and may be truncated. In order to resolve this link-time inconsistency, you must change the formid as it appears in the file created by VIFRED as instructed in Step 3.
3. Edit the C source file created by VIFRED that contains your compiled form. When you invoke the editor, find the line at the end of the file that begins with"FRAME * formid" where formid is the name of the form. Append an underscore to formid and truncate the name, if necessary. The following example shows the relevant lines of a C source file created by VIFRED where "empfrm" is the formid:
     ...

FRAME * empfrm = {
      &_empfrm, };
Modify the file to append the required underscore, as follows:
     ...

FRAME * empfrm_ = {
      &_empfrm, };
This example assumes that your compiler does not truncate external symbols.
Note:  You do not need to make changes to the declarations containing the formid in your Embedded SQL program. The Fortran compiler changes this reference when it creates the object file.
4. After modifying your C file, compile it into linkable object code with the UNIX command:
cc -c formfile.c
where "formfile.c" is the name of the compiled form source file created by VIFRED.
5. The output of this command is a file with the extension ".o". Link this object file with your program, as shown in the following example:
f77 -o formentry formentry.f \
     formfile.o \
     $II_SYSTEM/ingres/lib/libingres.a\
     -lm \
     -lc   
VMS:
To link a precomiled form
1. In VIFRED, select a menu item to compile a form. VIFRED then creates a file in your directory describing the form in the MACRO language. Select a name for the file.
2. Once you have created the MACRO file, assemble it into linkable object code with the VMS command:
macro filename
3. The output of this command is a file with the extension ".obj". Link this object file with your program by listing it in the link command, as shown in the following example:
link formentry,-
 empform.obj,-
 ii_system:[ingres.files]esql.opt/opt  
Windows:
To link a precomiled form
1. In VIFRED, select a menu item to compile a form. VIFRED then creates a C language file in your directory describing the form. Select a name for the file.
2. Once you have created the C language file, compile it into linkable object code with the Windows command:
    cl –c –MD filename
3. The output of this command is a file with the extension ".obj". Link this object file with your program by listing it in the link command, as shown in the following example:
link /out:formentry.exe, \
 empform.obj,\
 %II_SYSTEM%\ingres\lib\libingres.lib  
How Embedded SQL Programs are Linked without Shared Libraries -VMS
While the use of shared libraries in linking Embedded SQL programs is recommended for optimal performance and ease of maintenance, non-shared versions of the libraries have been included in case you need them. Non-shared libraries required by Embedded SQL are listed in the "esql.noshare" options file. The options file must be included in your link command after all user modules. The libraries must be specified in the order given in the options file.
The following example demonstrates the link command for an Embedded SQL program called "dbentry" that has been preprocessed and compiled:
link dbentry,-
 ii_system:[ingres.files]esql.noshare/opt
How to Place User-written Embedded SQL Routines in Shareable Images -VMS
When you plan to place your code in a shareable image, note the following about the psect attributes of your global or external variables:
As a default, some compilers mark global variables as shared (SHR: every user who runs a program linked to the shareable image sees the same variable) and others mark them as not shared (NOSHR: every user who runs a program linked to the shareable image gets their own private copy of the variable).
Some compilers support modifiers you can place in your source code variable declaration statements to explicitly state which attributes to assign a variable.
The attributes that a compiler assigns to a variable can be overridden at link time with the psect_attr link option. This option overrides attributes of all variables in the psect.
Consult your compiler reference manual for further details.
Last modified date: 01/30/2023