[mercury-users] Making a Mercury shared library

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Jun 3 13:58:10 AEST 2011

On Fri, 3 Jun 2011, Guillaume Yziquel wrote:

> Le Thursday 02 Jun 2011 à 23:47:01 (+0200), Guillaume Yziquel a écrit :
>> Hi.
>> I wish to make a shared library out of mercury code that I would call
>> from an OCaml or C program. I haven't found information about how to use
>> mmc to do that. Could someone quickly explain how to do that or pinpoint
>> some documentation about that?
>> Best regards,
> OK. Found out how to build a shared library and link it with my OCaml
> code. However, I have some trouble with what seems to initialisation of
> mercury engine:
> yziquel at seldon:~/sandbox$ make
> mmc --pic -c hello.m
> gcc -I /usr/local/mercury-11.01/lib/mercury/inc -I /usr/local/mercury-11.01/lib/mercury/conf -fPIC -c hello_stubs.c
> ml --make-shared-lib -o libhello.so hello.pic_o hello_stubs.o
> ocamlc -o fibo.byte -dllpath . -dllib libhello.so fibo.ml
> yziquel at seldon:~/sandbox$ ./fibo.byte 2
> ocamlrun: mercury_engine.c:512: call_engine_inner: Assertion `(MR_engine_base.MR_eng_this_context)' failed.
> Abandon
> yziquel at seldon:~/sandbox$
> What should I do to properly initialise the engine from foreign code?

See the ``Stand-alone Interfaces'' section of the User's guide for
details of how to do this.  There is an example in


More information about the users mailing list