next up previous index
Next: Restrictions and Recommendations Up: External Predicates in C Previous: Coding External Predicates   Index

Compiling and loading

It is strongly recommended to copy the makefile "Makefile.external" provided in your installation directory under lib/$ARCH and adapt it for your purposes. If the makefile is not used, the command to compile a C source with ECLiPSe library calls looks something like this:
 % cc -G -I/usr/local/eclipse/include/sparc_sunos5
-o eg_externals.so eg_externals.c
or
 % cc -shared -I/usr/local/eclipse/include/i386_linux
-o eg_externals.so eg_externals.c
If the external is to be used in a standalone ECLiPSe, it is possible to dynamically load it using the load/1 predicate:
    load("eg_externals.so")
On older UNIX platforms without dynamic loading, the following method may work. Compile the source using
 % cc -c -I/usr/local/eclipse/include/sparc_sunos5 eg_externals.c
and load it with a command like
    load("eg_externals.o -lg -lm")
The details may vary depending on what compiler and operating system you use. Refer to the Makefile.external for details.

Once the object file containing the C function has been loaded into ECLiPSe, the link between the function and a predicate name is made with external/2

    external(sumlist/2, p_sumlist)
The new predicate can now be called like other predicates. Note that the external/2 declaration must precede any call to the declared predicate, otherwise the ECLiPSe compiler will issue an inconsistent redefinition error. Alternatively, the external/1 forward declaration can be used to prevent this.


next up previous index
Next: Restrictions and Recommendations Up: External Predicates in C Previous: Coding External Predicates   Index
Warwick Harvey
2004-08-07