
7.2 Overview of the FI
hello.c:
#include <stdio.h>Note thatint hello(char *str, int num) { printf("%s %i\n", str, num); return(42 + num); }
hello.c does not contain a main function -- it is instead providing a shared library, albeit a trivial one.
Compile the hello.c file using your favourite C compiler to create an object file, and from that a shared object file. A sample makefile to do this might look like this (on SunOS 4.1.3):
hello.o: hello.c $(CC) $(CFLAGS) -c hello.c -o hello.oThe variants for Solaris and IRIX are fairly trivial. A suitable makefile for your are available in the Foreign Interface distribution under the directoryhello.so: hello.o $(LD) -Bdynamic hello.o -o hello.so
foreign/samples/.
To make use of UNIX shared libraries from MLWorks (and indeed in general) it is very important to set the LD_LIBRARY_PATH environment variable appropriately. For correct operation, the path must include the current directory (.) and the standard shared-object systems directory (usually /usr/lib). This path is very sensitive to ordering, so if you have difficulty with it, experiment with different orderings and do not rely on the documented defaults.

Generated with Harlequin WebMaker