[howto] ldap4pl + msys2-x64 + Win10

How to get ldap4pl to compile under msys2-x64:

  1. Get MSYS2 working (installed, updated), install needed dependencies
  • base_devel [for make, etc.]
  • mingw-w64-x86_64-toolchain [gcc et. al.]
  • mingw-w64-x86_64-openldap [openldap]
  1. start the mingw64.exe shell launcher
  2. start swipl-win (or swipl) from the mingw terminal
  3. ?- pack_install(ldap4pl).
  • and let it fail:

      ERROR: c/ldap4pl.c: In function 'build_timeval':
      ERROR: c/ldap4pl.c:755:40: warning: passing argument 2 of 'PL_get_long' from incompatible pointer type [-Wincompatible-pointer-types]
      ERROR:              if (!PL_get_long(tv_sec_t, &tv_sec)) {
      ERROR:                                         ^~~~~~~
      ERROR: In file included from c/ldap4pl.c:17:
      ERROR: c:/swipl/include/SWI-Prolog.h:460:45: note: expected 'long int *' but argument is of type 'time_t *' {aka 'long long int *'}
      ERROR:  PL_EXPORT(int)  PL_get_long(term_t t, long *i) WUNUSED;
      ERROR:                                        ~~~~~~^
      ERROR: c/ldap4pl.c:767:13: error: unknown type name 'suseconds_t'; did you mean 'useconds_t'?
      ERROR:              suseconds_t tv_usec;
      ERROR:              ^~~~~~~~~~~
      ERROR:              useconds_t
      ERROR: make: *** [Makefile:19: c/ldap4pl.o] Error 1
      % gcc  -I"c:/swipl/include" -std=c99 -DLDAP_DEPRECATED -c -o c/ldap4pl.o c/ldap4pl.c
      ERROR: Process "process(path(make),[all])": exit status: 2
      ERROR: In:
      ERROR:   [14] throw(error(process_error(...,...),_7266))
      ERROR:   [12] '$apply':forall('<garbage_collected>',prolog_pack:run_process(...,...,...)) at c:/swipl/boot/apply.pl:51
      ERROR:    [7] <user>
      ERROR: 
      ERROR: Note: some frames are missing due to last-call optimization.
      ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
    

edit the .c file in the pack, replace “suseconds_t” with “useconds_t” as suggested, and replace PL_get_long with PL_get_int64 for both tv_sec and tv_usec in build_timeval (currently lines 755 & 769).

  1. Now it would compile, but the build process hung (in swipl, not in cmdline) for me. I had to also edit the Makefile.

Change the LIBS line to read:

LIBS=-lldap -llber

and the last line of the ‘$(SOBJ): c/ldap4pl.o’ target from:

$(LD) $(LDSOFLAGS) $(SWISOLIB) -o $@ $< $(LIBS)

to:

$(CC) -shared $(LDSOFLAGS) -o $@ $< $(SWISOLIB) $(LIBS)

after this, [in swipl]

?- pack_rebuild(ldap4pl).

and it builds.

  1. unless you wanna put the msys/mingw bin dir on your system path, copy the following dlls from <msys64>\mingw64\bin dir into <swipl>\bin dir:
  • liblber.dll
  • libldap.dll
  • libldap_r.dll
  • libsasl2-3.dll

I’m able to bind to ActiveDirectory & execute queries without segfaults (although whether the diacritics are just badly showing in the swipl-win console, or whether the returned data are malformed is yet to be determined).

I don’t have any idea how to update the pack and not break other environments, so I’m just reporting [at least partial] success.

PS: When troubleshooting the build outside of swipl, the following cmdline proved useful:

CC=gcc CPATH="/c/swipl/include" LDSOFLAGS="-L/c/swipl/bin" PACKSODIR="/C/swipl/pack/ldap4pl/lib/x64-win64" SOEXT="dll" SWISOLIB="-lswipl" make