[m-users.] Using the. 'Extras' modules, specifically posix

Julien Fischer jfischer at opturion.com
Wed Apr 21 17:16:09 AEST 2021


Hi Sean,

On Tue, 20 Apr 2021, Sean Charles (emacstheviking) wrote:

> I followed the instructions on how to build this library.It installed lots of files into here, for example:
> 
>     /usr/local/mercury-rotd-2021-04-15/extras/lib/mercury/inc/posix.kill.mh
> 
> When I try to import it I get an error, it can’t find it. The build
> process seemed to know where to put it so how do I tell it where to
> find it, I possibly naively assumed it would be automatic?

For a library other than standard library, you need to tell the compiler
that (1) you want to use it and (2) where it is.  How you do that
depends on which of the Mercury build systems you are using to build
your program.

If you're using mmc --make or just building directly using mmc, pass
the following options to the compiler (as well as any others you
require):

    --ml posix --mld /usr/local/mercury-rotd-2021-04-15/extras/lib/mercury

(Or set the in a Mercury.options file.)

If you're using mmake to build your program set the following in your
Mmakefile:

    EXTRA_LIB_DIRS = /usr/local/mercury-rotd-2021-04-15/extras/lib/mercury
    EXTRA_LIBRARIES = posix

> I have —zero— knowledge of Mmake and any command line magic.

The relevant sections of the Users's guide are "6.2.2 Using installed
libararies with mmc --make" and "6.3.3. Using libraries with Mmake".

> Here is my meagre excuse of a program, for educational purposes I wanted to write a little app that could scan the `cwd` for all files ending in
> `.m` then remove any build files. Yes, I know I can tell it to explicitly use a folder and also I could write a makefile and do `make clean` but
> then I wouldn’t be learning Mercury would I?
> 
> :- module mwipe.
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is det.
> :- implementation.
> :- import_module dir, list, posix, string.
> 
> main(!IO) :-
>     dir.current_directory(D, !IO),
>     (   D = ok(Dir),
>         io.format("looking for crufty files in %s...\n", [s(Dir)], !IO)
>     ;
>         D = error(_),
>         io.format("oops: \n", [], !IO)
>     ).
> 
> And the error:
> 
>     mercury_compile: cannot find `posix.int' in directories .,
>       /usr/local/mercury-rotd-2021-04-15/lib/mercury/ints

By default the compiler will only search for library files where the
standard library is installed (/usr/local/mercury/rotd-2021-04-15/lib in
your case).  If you want to use libaries installed into
/usr/loca/mercury-rotd-2021-04-15 you need to tell it to search there.

Julien.


More information about the users mailing list