How do I use functions from external libraries in a Gedae function box?
The instructions for altering the flags in the make system in order to link in external functions depend on the operating system and the type of library or files being linked in. If include files are used, the flags used during compilation can be altered to add include file directories. If the box is to be run on an embedded processor, separate steps must be taken to link in the external functions during this part of the compilation process.
Windows
When Gedae compiles a function box on Windows, a .DLL (Dynamically Linked Library) file is created, and then that .DLL file is accessed from within Gedae. Because all symbols must be resolved when creating a DLL, we recommend that all external libraries and files used in boxes be treated as static libraries. Thus, the external libraries must be linked into each function box .DLL file.
The Gedae make system is able to link in libraries during the creation and compilation of each box. To do this, open the makeGEDAE file in an editor. Find the line that sets the environment variable FNC_BOX_LIBS (or create one if one does not exist), and add the new external libraries to this variable.
The Windows command-line C-compiler and linker uses the flag -libpath: to add a directory to the library search path and the flag -defaultlib: to add a library.
For example, if the library z.lib from directory c:\my_libs is being added and the FNC_BOX_LIBS variable is currently set to
$ENV{"FNC_BOX_LIBS"} = "-nodefaultlib:libc -defaultlib:msvcrt
-defaultlib:winmm $XLIB";
in the makeGEDAE file, then change this line to:
$ENV{"FNC_BOX_LIBS"} = "-nodefaultlib:libc -defaultlib:msvcrt
-defaultlib:winmm $XLIB -libpath:c:/my_libs
-defaultlib:z";
(Note: Use forward slashes when adding directories to include and library paths in this makefile, even on NT systems.)
Whenever a box is compiled, these libraries will now be used in the compilation. The user may want to clear out old object files for boxes to force a re-compilation the next time a box is added to the canvas by doing
makeGEDAE CLEAN
makeGEDAE
before launching Gedae.
Solaris and Redhat Linux
When Gedae compiles a function box on Unix, a .SO (Shared Object) file is created, and then that .SO file is accessed from within Gedae. The Unix dynamic library system allows symbols in the .SO file to remain unresolved until the box is used in Gedae. Thus, dynamic external libraries need only be linked into the Gedae executable, and the operating system will handle resolving the symbols when the box is used.
The Gedae make system allows libraries to be added to the final linking of the Gedae executable. If dynamic libraries are linked into the executable on Unix-variant systems, functions in these libraries will be available to boxes running on the host. To do this, open the Personal_Obj_List file in an editor (located in the subdirectory of the user directory that contains the Gedae executable). Find the line that sets the script variable PERSONAL_LIBS (or create one if one does not exist), and add the dynamic external libraries to this variable.
Unix C-compilers and linkers uses the flag -L to add a directory to the library search path and the flag -l to add a library. For example, if the shared object file libz.so from directory /usr/lib/my_libs is being added and the PERSONAL_LIBS variable is currently set to
PERSONAL_LIBS = $(AUDIOLIB)
in the Personal_Obj_List file, then change this line to
PERSONAL_LIBS = $(AUDIOLIB) -L/usr/lib/my_libs -lz
Performing a "makeGEDAE" will now link in these libraries.
Many libraries on Unix systems are not dynamic, however. Library files ending in .a are static libraries. Just as in the discussion above on the Windows operating system, static libraries must be linked into each function box.
To link in libraries during the creation and compilation of each box, open the makeGEDAE file in an editor. Find the line that sets the environment variable FNC_BOX_LIBS (or create one if one does not exist), and add the new static external libraries to this variable. For example, if the library libz.a from directory /home/me/my_libs is being added and the FNC_BOX_LIBS variable is currently set to
$ENV{"FNC_BOX_LIBS"} = "-L/usr/lib -lother";
in the makeGEDAE file, then change this line to
$ENV{"FNC_BOX_LIBS"} = "-L/usr/lib -lother -L/home/me/my_libs -lz";
Whenever a box is compiled, these libraries will now be used in the compilation. The user may want to clear out old object files for boxes to force a re-compilation the next time a box is added to the canvas by doing
makeGEDAE CLEAN
makeGEDAE
before launching Gedae.
Include Files
To use these external libraries in a function box, function prototypes are needed so the box can compile cleanly. As described in the Primitive Programming Manual, the Include section of the box can be used to add include files that contain these prototypes. However, when using external libraries, often the make system must be changed to add directories to the search path for include files.
If there are directories of include files that need to be added to the include search path, alter the CFLAGS variable in the makeGEDAE file. For example, if the include directory is c:\my_includes and the CFLAGS variable is currently set to
$ENV{"CFLAGS"} = "-Z7 -D_COMPLEX_DEFINED -DWIN32 -nologo -D_NT_";
in the makeGEDAE file, then change this line to
$ENV{"CFLAGS"} = "-Z7 -D_COMPLEX_DEFINED -DWIN32 -nologo -D_NT_ -Ic:/my_includes";
(Note: Use forward slashes when adding directories to include and library paths in this makefile, even on NT systems.)
Compiling and Linking in C-Files
The Gedae make system allows C code to be compiled and linked into the Gedae executable (as well as being available to be linked into each box). To do this, first place the .c files in the "source" directory (the directory named "source" which is a subdirectory of the user directory). Then, open the Personal_Obj_List file in an editor (located in the subdirectory of the user directory that contains the Gedae executable). Find the line that sets the script variable PERSONAL_HOST_FILES (or create one if one does not exist), and add the names of the object files corresponding to the C-files to this variable, e.g., if the files x.c, y.c, and z.c are being compiled and linked into Gedae and the PERSONAL_HOST_FILES variable is current set to
PERSONAL_HOST_FILES =
in the Personal_Obj_List file, then change this line to
PERSONAL_HOST_FILES = x.o y.o z.o
Include files used along with these C-files should be put in the directory named "include" which is parallel to the "source" directory. This "include" directory is automatically added to the include search path. Include files placed in this directory are automatically available to be included in the Include: section of a Gedae primitive.
Performing a "makeGEDAE" will compile these C-files, linking them into the Gedae executable. Note this does not necessarily mean the functions in these C-files are now available in boxes; depending on the host system, directions above must also be followed so that the functions are also linked into the box.
Using External Functions on Embedded Systems
To this point, everything in this FAQ has explained how to access external functions in boxes running on the host. To access such functions on Embedded Systems (including thread-based systems like Ent, Esolaris, and Eredhat), steps parallel to those mentioned above must be completed for the parallel system.
The files altered in when adding external libraries to boxes running on the host are makeGEDAE and Personal_Obj_List. In the directory that contains these files there is also a directory named "embedded". This embedded directory has a subdirectory for each embedded system configured for the current machine.
For example, each NT installation has an embedded\ent subdirectory for the Ent system, and each Solaris installation has an embedded/esolaris subdirectory for the Esolaris system. In each of these directories there are two files, runtime_make_info and Personal_Emb_Obj_List, and these files are meant to parallel makeGEDAE and Personal_Obj_List for compiling for the embedded system.
To link in libraries and add directories of include files, alter EMB_LIBS and EMB_CFLAGS in the runtime_make_info file, similar as to what is done in previous sections with the FNC_BOX_LIBS and CFLAGS variables. When Gedae compiles the executable to be run on the embedded processor, these flags and libraries will be included. To link in uncompiled C-files, list the corresponding object files in the MY_EMB_FILES variable in the Personal_Emb_Obj_list file, similar as to what is done with the PERSONAL_HOST_FILES variable. The make system will compile and link in the C-files during the creation of the embedded executable.
return to top