EGL programs can invoke C functions through Library parts with the stereotype nativeLibrary.
Your C code receives values from EGL using pop external functions and returns values to EGL using return external functions.
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
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
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 a previous step.
#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.
The application object file is the interface between the EGL code and the C code.
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.