Extending the language / C-Extensions |
This example shows how to create a C-Extension library on Linux™ using gcc.
The command line options to compile and link shared libraries can change depending on the operating system and compiler/linker used.
#include <string.h> #include "f2c/fglExt.h" int fgl_split( int in_num ); int fgl_split( int in_num ) { char c1[101]; char c2[101]; char z[201]; char *ptr_in; char *ptr_out; popvchar(z, 200); /* Getting input parameter */ strcpy(c1, ""); strcpy(c2, ""); ptr_out = c1; ptr_in = z; while (*ptr_in != ' ' && *ptr_in != '\0') { *ptr_out = *ptr_in; ptr_out++; ptr_in++; } *ptr_out=0; ptr_in++; ptr_out = c2; while (*ptr_in != '\0') { *ptr_out = *ptr_in; ptr_out++; ptr_in++; } *ptr_out=0; pushvchar(c1, 100); /* Returning the first output parameter */ pushvchar(c2, 100); /* Returning the second output parameter */ return 2; /* Returning the number of output parameters (MANDATORY) */ }
#include "f2c/fglExt.h" int fgl_split(int); UsrFunction usrFunctions[]={ { "fgl_split", fgl_split, 1, 2 }, { 0,0,0,0 } };
gcc -c -I $FGLDIR/include -fPIC split.c gcc -c -I $FGLDIR/include -fPIC splitext.c
gcc -shared -o libsplit.so split.o splitext.o -L$FGLDIR/lib -lfgl
IMPORT libsplit MAIN DEFINE str1, str2 VARCHAR(100) CALL fgl_split("Hello World") RETURNING str1, str2 DISPLAY "1: ", str1 DISPLAY "2: ", str2 END MAIN
fglcomp split.4gl
fglrun split