[m-users.] Can't compile sample programn

Julien Fischer jfischer at opturion.com
Thu Mar 21 15:31:33 AEDT 2019



On Wed, 20 Mar 2019, Volker Wysk wrote:

> Am Mittwoch, 20. März 2019, 02:35:39 CET schrieb Julien Fischer:
>> As Mark has mentioned, that library is only set up for building using
>> mmake.  The  reason you get the above error with mmc --make is that
>> there is a chunk of C code (in posix_workarounds.c) that needs to be
>> separately compiled into an object file and included in the Mercury
>> library and then the corresponding C header file (posix_workarounds.h)
>> needs to be installed alongside the header files generated by the
>> Mercury compiler.
>
>> If you did want to compile it using mmc --make, then you need to do
>> something like the following:
>> 
>> 1. Compile posix_workaround into an object file.
>> 2. Invoke mmc --make with the following options:
>>
>>     $ mmc --link-object posix_workarounds.o  \
>>           --extra-library-header posix_workarounds.h
>>           --make libposix
>> 
>> Since the POSIX binding only supports C grades, you probably also want
>> to prevent mmc --make from attempting to install the library in non-C
>> grades.  That can be done by applying an exclusion to the libgrade set.
>>
>>     $ mmc --link-object posix_workarounds.o  \
>>           --extra-library-header posix_workarounds.h
>>           --libgrades-exclude java \
>>           --libgrades-exclude csharp \
>>           --libgrades-exclude erlang \
>>           --make libposix

Note that the above command just builds the posix library, if you want
to install you will need to make the target libposix.install.

> When the library is set up for building with mmake, I use mmake. That's fine. 
> I've built and successfully installed it that way.
>
> But I think you should be able to use it with mmc --make, after it has been 
> installed successfully. Isn't it?

Yes, you can.

> When I do this:
>
> cd /usr/local/src/mercury-srcdist-rotd-2019-03-12/extras/posix

Where did you install the library?

> rm hello
> LANG=C mmc --make hello --ml posix

Unless you have installed the library in the default installation
directory (i.e. where Mercury's standard library is installed) then I
would expect to also see the --mld option on the command line telling
the Mercury compiler where the posix library is installed.

> I get this:
>
> Making hello
> ** Error making `hello'.
> Mercury/os/posix.select.o: In function `<predicate 
> 'posix:select.new_fdset_ptr'/3 mode 0>':
> posix.select.c:(.text+0x291): undefined reference to `ME_fd_zero'
> Mercury/os/posix.select.o: In function `<predicate 'posix:select.fd_zero'/3 
> mode 0>':
> posix.select.c:(.text+0x2cc): undefined reference to `ME_fd_zero'
> Mercury/os/posix.select.o: In function `<predicate 'posix:select.fd_clr'/4 
> mode 0>':
> posix.select.c:(.text+0x2ff): undefined reference to `ME_fd_clr'
> Mercury/os/posix.select.o: In function `<predicate 'posix:select.fd_isset'/5 
> mode 0>':
> posix.select.c:(.text+0x33f): undefined reference to `ME_fd_isset'
> Mercury/os/posix.select.o: In function `<predicate 'posix:select.fd_set'/4 
> mode 0>':
> posix.select.c:(.text+0x37f): undefined reference to `ME_fd_set'
> collect2: error: ld returned 1 exit status

Attempting to build hello using mmc --make in the _same_ directory as
the posix library source files will just recompile those source files;
it won't use the installed version of the library at all.  If you don't
include the extra object file via --link-object then you will get the
above error.

(mmake can get away with the files all being in the same directory,
mmc --make won't.)

> I've tried it with --link-object posix_workarounds.o and --extra-library-
> header posix_workarounds.h, like you've written. This works. But I think this 
> shouldn't be necessary to specify every time, after the library has been 
> correctly installed. Am I right?

That statment is correct.  The issue here is because you are in the same
directory as the library source files you are *not* using the installed
version of hte posix library, just recompiling its source files.

For reference:

To install the library using mmc --make

    $ cd extras/posix
    $ cc -c posix_workarounds.c
    $ mmc --link-object posix_workarounds.o \
            --extra-library-header posix_workarounds.h \
            --libgrades-exclude java \
            --libgrades-exclude csharp \
            --libgrades-exclude erlang \
            --install-prefix /where/to/install/it \
            --make libposix.install

To then compile hello.m using the library, from some directory other
than extras/posix do:

     $ mmc --ml posix --mld /where/to/install/it/lib/mercury --make hello

(Obviously, you need to replace /where/to/install/it with the actual
installation directory.)

Julien.


More information about the users mailing list