C functions with EGL

EGL programs can invoke C functions.

To invoke a C function from EGL:

After you have identified the C functions to use in your EGL program, you must:
  1. Download the EGL stack library and application object file from the IBM® website to your computer.
  2. Compile all C code into one shared library and link it with the appropriate platform-specific stack library.
  3. Create a function table.
  4. Compile the function table and the appropriate platform-specific application object file into a shared library, and link this shared library with the shared library created in Step 2 and the stack library.

1. Download the EGL stack library and application object file

To download the EGL stack library and application object file:
  1. Locate the EGL Support website.
    • The URL for Rational® Application Developer is:
      http://www3.software.ibm.com/ibmdl/pub/software/rationalsdp/rad/60/redist
    • The URL for Rational Web Developer is:
      http://www3.software.ibm.com/ibmdl/pub/software/rationalsdp/rwd/60/redist 
    .
  2. Download the EGLRuntimesV60IFix001.zip file to your preferred directory.
  3. Unzip EGLRuntimesV60IFix001.zip to identify the following files:
For the platform-specific stack libraries: .
For the platform-specific application object files: .

2. Compile all C code into a shared library

Your C code receives values from EGL using pop external functions and returns values to EGL using return external functions. The pop external functions are described in Receiving values from EGL; the return external functions are described in Returning values to EGL.

To compile all C code into a shared library:
  1. Using standard methods, compile all of your C code into one shared library and link it with the appropriate platform-specific EGL stack library.
  2. In the following platform-specific examples, file1.c and file2.c are C files containing functions invoked from EGL.

    On AIX (the ld command must be on a single line):
    cc -c -Iincl_dir  file1.c file2.c
    ld -G -b32 -bexpall -bnoentry 
       -brtl file1.o file2.o -Lstack_lib_dir 
       -lstack -o lib1_name -lc

    On Linux (the gcc command must be on a single line):
    cc -c -Iincl_dir  file1.c file2.c
    gcc -shared file1.o file2.o -Lstack_lib_dir
        -lstack -o lib1_name

    On Windows® (the link command must be on a single line):

    cl /c -Iincl_dir file1.c file2.c 
    link /DLL file1.obj file2.obj 
         /LIBPATH:stack_lib_dir 
         /DEFAULTLIB:stack.lib /OUT:lib1_name
    incl_dir
    the directory location for the header files.
    stack_lib_dir
    the directory location for the stack library.
    lib1_name
    the name of the output library.
Note: If your C code is using any of the IBM Informix® ESQL/C library functions (BIGINT, DECIMAL, DATE, INTERVAL, DATETIME), then the ESQL/C library must also be linked.

3. Create a function table

The function table is a C source file which includes the names of all C functions to be invoked from the EGL program. In the following function table example, c_fun1 and c_fun2 are names of the C functions. All of the functions identified in the code must have been exported from the C shared library created in Step 2 above.

#include <stdio.h>
struct func_table {

      char *fun_name;
      int (*fptr)(int); 
};

extern int c_fun1(int);
extern int c_fun2(int);
/* Similar prototypes for other functions */

struct func_table ftab[] =
            {
                 "c_fun1", c_fun1,
                 "c_fun2", c_fun2,
                 /* Similarly for other functions */
                 "", NULL
            };  

Create a function table based on the example above, and populate the function table with the appropriate C functions. Indicate the end of the function table with "", NULL.

4. Compile the function table and the platform-specific application object file into a shared library

The application object file is the interface between the EGL code and the C code.

The following two artifacts must be compiled into one shared library and linked with the stack library and the library created in Step 2 above:

Compile the new shared library using the following example, where ftable.c is the name of the function table and mylib is the name of the C shared library created in Step 2 and lib_dir is the directory location for mylib. Specify lib2_name by using the dllName property or the vgj.defaultI4GLNativeLibrary Java™ runtime property.

On AIX (the ld command must be on a single line):

cc -c  ftable.c
ld -G -b32 -bexpall -bnoentry 
   -brtl ftable.o application.o 
   -Lstack_lib_dir -lstack -Llib_dir 
   -lmylib -o lib2_name -lc

On Linux (the gcc command must be on a single line):

cc -c  ftable.c
gcc -shared ftable.o application.o 
    -Lstack_lib_dir -lstack -Llib_dir 
    -lmylib -o lib2_name

On Windows (the link command must be on a single line):

cl /c ftable.c
link /DLL ftable.obj application.obj 
     /LIBPATH:stack_lib_dir 
     /DEFAULTLIB:stack.lib 
     /LIBPATH:lib_dir 
     /DEFAULTLIB:mylib.lib /OUT:lib2_name

Link the three libraries together.

With your C shared library, function table, and stack library linked, you are now ready to invoke the C functions from your EGL code. For information on how to invoke a C function in EGL, see Invoking a C function from an EGL program.

Related concept
Linkage options part

Related reference
BIGINT functions for C
C data types and EGL primitive types
DATE functions for C
DATETIME and INTERVAL functions for C
DECIMAL functions for C
Invoking a C Function from an EGL Program
Return functions for C
Stack functions for C

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.