[m-users.] Building Mercury Modules with Functions to be Called from C
jfischer at opturion.com
Wed Sep 12 23:27:17 AEST 2018
On Wed, 12 Sep 2018, Charles Shuller wrote:
> When attempting to build a library of mercury functions to be called
> from C, I wind up individually compiling to C, then using C tools for
> everything else. Is there a better approach??
> What I've got working in my Proof of Concept is to compile each module separately with:
> mmc --grade hlc --compile-to-c min.m
> And then use my C compiler (gcc) on the output C file.
That's likely to be error prone; Mercury is very particular about
how it uses the C compiler.
> In larger apps, I'd like to try and mirror the approach I use with C,
> which is to build a convenience library (i.e. a static lib that is
> only ever used by main and unit tests of the project, and is
> statically linked against) and call into mercury modules from there.
See the example in samples/c_interface/standalone_c for how to call
Mercury from external C and C++ code; the approach used there should
extend fairly easily to the situation you describe.
(The documentation for that sample is in the Makefile in that
> I thought there was a command that would easily do that, something
> like: mmc --make my_lib.a, but I can't find the docs anymore.
The command should be:
$ mmc --make libmy_lib.a
With mmc --make targets for building libraries must have the prefix
"lib" in front of them.
(See the section 6.2 ``Building with mmc --make'' in the User's guide.)
More information about the users