The following short piece of C code is in hello.c:
#include <stdio.h>
int hello(char *str, int num)
{
printf("%s %i\n", str, num);
return(42 + num);
}
Note that 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 Solaris 2.5):
hello.o: hello.c $(CC) $(CFLAGS) -c hello.c -o hello.o hello.so: hello.o $(LD) -Bdynamic -G -lgen hello.o -o hello.so
The variants for Linux and IRIX are fairly trivial. A suitable makefile for the platform on which you are running MLWorks is available in the Foreign Interface distribution under the directory 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.