I'm having difficulty linking a custom
external C function into MonetDB without crashing the database
connection. If anyone knows of a documented end-to-end example of
adding external functions compiled with GCC, please let me
know. I've documented a minimal
example below that crashes the connection for me each time.
Software:
Red Hat Linux knock-off CentOS, i386.
Most recent MonetDB download from Sourceforge
(server 5.2.2, client 1.20.2, common 1.20.0).
GCC 4.1.1
1. Create a simple C file named
te.c.
int
TEtest( )
{
return 4;
}
2. Compile file, move it to the proper
directory, and create symlinks.
$ gcc -c -fPIC te.c -o te.o
$ gcc -shared -Wl,-soname,lib_te.so.0 -o
lib_te.so.0.0.0 te.o (also tried with soname = libte.so.0, leaving
output as lib_te.so.0.0.0)
$ cp lib_te.so.0.0.0
$mhome/lib/MonetDB5/lib
$ cd $mhome/lib/MonetDB5/lib
$ ln -s lib_te.so.0.0.0
lib_te.so.0
$ ln -s lib_te.so.0.0.0
lib_te.so
3. Create a MAL file, saved as $mhome/lib/MonetDB5/te.mal
module te;
command test( ):int
address TEtest();
command doesnotexist( ):int
address TEdoesnotexist;
4. Update mal_init.mal by adding the following 2 lines:
library te;
include te;
5. Start a random DB and try to invoke the test function.
Merovingian log show database dino killed by signal 11 afterwards.
$ cd $mhome/bin
$ ./merovingian &
[1] xxxx
$ ./mclient -lmal --database=dino -h COS1
mal> te.test( );
ACTION= read_line
QUERY = te.test();
ERROR = Connection terminated
If I instead invoke te.doesnotexist(), I get a different error
(below.) This leads me to think that MonetDB is findng and loading my
compiled .so file, but it wasn't compiled correctly or otherwise isn't
providing what MonetDB expects.
mal> te.doesnotexist();
QUERY = te.doesnotexist();
ERROR = !TypeException:user.main[1]:'te.doesnotexist' undefined in: _1:int
:= te.doesnotexist()
Any pointers are appreciated.
Thomas Schulte