-DSWIPL_M32, compiling 32bit prolog under 64bit host fails

swi-prolog is not compiling the 32bit version on a 64bit host by using the SWIPL_M32 flag. The problem maybe comes from the new gmp cmake code for wasm:

[1/2099] Linking C shared library src/libswipl.so.8.5.15
FAILED: src/libswipl.so.8.5.15 
: && /usr/sbin/cc -fPIC -m32 -O2   -shared -Wl,-soname,libswipl.so.8 -o src/libswipl.so.8.5.15 src/CMakeFiles/swiplobjs.dir/pl-atom.c.o src/CMakeFiles/swiplobjs.dir/pl-wam.c.o src/CMakeFiles/swiplobjs.dir/pl-arith.c.o src/CMakeFiles/swiplobjs.dir/pl-bag.c.o src/CMakeFiles/swiplobjs.dir/pl-error.c.o src/CMakeFiles/swiplobjs.dir/pl-comp.c.o src/CMakeFiles/swiplobjs.dir/pl-zip.c.o src/CMakeFiles/swiplobjs.dir/pl-dwim.c.o src/CMakeFiles/swiplobjs.dir/pl-ext.c.o src/CMakeFiles/swiplobjs.dir/pl-flag.c.o src/CMakeFiles/swiplobjs.dir/pl-funct.c.o src/CMakeFiles/swiplobjs.dir/pl-gc.c.o src/CMakeFiles/swiplobjs.dir/pl-privitf.c.o src/CMakeFiles/swiplobjs.dir/pl-list.c.o src/CMakeFiles/swiplobjs.dir/pl-string.c.o src/CMakeFiles/swiplobjs.dir/pl-load.c.o src/CMakeFiles/swiplobjs.dir/pl-modul.c.o src/CMakeFiles/swiplobjs.dir/pl-op.c.o src/CMakeFiles/swiplobjs.dir/pl-prims.c.o src/CMakeFiles/swiplobjs.dir/pl-pro.c.o src/CMakeFiles/swiplobjs.dir/pl-proc.c.o src/CMakeFiles/swiplobjs.dir/pl-prof.c.o src/CMakeFiles/swiplobjs.dir/pl-read.c.o src/CMakeFiles/swiplobjs.dir/pl-rec.c.o src/CMakeFiles/swiplobjs.dir/pl-setup.c.o src/CMakeFiles/swiplobjs.dir/pl-sys.c.o src/CMakeFiles/swiplobjs.dir/pl-trace.c.o src/CMakeFiles/swiplobjs.dir/pl-util.c.o src/CMakeFiles/swiplobjs.dir/pl-wic.c.o src/CMakeFiles/swiplobjs.dir/pl-write.c.o src/CMakeFiles/swiplobjs.dir/pl-term.c.o src/CMakeFiles/swiplobjs.dir/pl-thread.c.o src/CMakeFiles/swiplobjs.dir/pl-xterm.c.o src/CMakeFiles/swiplobjs.dir/pl-srcfile.c.o src/CMakeFiles/swiplobjs.dir/pl-beos.c.o src/CMakeFiles/swiplobjs.dir/pl-attvar.c.o src/CMakeFiles/swiplobjs.dir/pl-gvar.c.o src/CMakeFiles/swiplobjs.dir/pl-btree.c.o src/CMakeFiles/swiplobjs.dir/pl-init.c.o src/CMakeFiles/swiplobjs.dir/pl-gmp.c.o src/CMakeFiles/swiplobjs.dir/pl-segstack.c.o src/CMakeFiles/swiplobjs.dir/pl-hash.c.o src/CMakeFiles/swiplobjs.dir/pl-version.c.o src/CMakeFiles/swiplobjs.dir/pl-codetable.c.o src/CMakeFiles/swiplobjs.dir/pl-supervisor.c.o src/CMakeFiles/swiplobjs.dir/pl-dbref.c.o src/CMakeFiles/swiplobjs.dir/pl-termhash.c.o src/CMakeFiles/swiplobjs.dir/pl-variant.c.o src/CMakeFiles/swiplobjs.dir/pl-assert.c.o src/CMakeFiles/swiplobjs.dir/pl-copyterm.c.o src/CMakeFiles/swiplobjs.dir/pl-debug.c.o src/CMakeFiles/swiplobjs.dir/pl-cont.c.o src/CMakeFiles/swiplobjs.dir/pl-ressymbol.c.o src/CMakeFiles/swiplobjs.dir/pl-dict.c.o src/CMakeFiles/swiplobjs.dir/pl-trie.c.o src/CMakeFiles/swiplobjs.dir/pl-indirect.c.o src/CMakeFiles/swiplobjs.dir/pl-tabling.c.o src/CMakeFiles/swiplobjs.dir/pl-rsort.c.o src/CMakeFiles/swiplobjs.dir/pl-mutex.c.o src/CMakeFiles/swiplobjs.dir/pl-allocpool.c.o src/CMakeFiles/swiplobjs.dir/pl-wrap.c.o src/CMakeFiles/swiplobjs.dir/pl-event.c.o src/CMakeFiles/swiplobjs.dir/pl-transaction.c.o src/CMakeFiles/swiplobjs.dir/pl-undo.c.o src/CMakeFiles/swiplobjs.dir/pl-alloc.c.o src/CMakeFiles/swiplobjs.dir/pl-index.c.o src/CMakeFiles/swiplobjs.dir/pl-fli.c.o src/CMakeFiles/swiplobjs.dir/pl-coverage.c.o src/CMakeFiles/swiplobjs.dir/os/pl-buffer.c.o src/CMakeFiles/swiplobjs.dir/os/pl-ctype.c.o src/CMakeFiles/swiplobjs.dir/os/pl-file.c.o src/CMakeFiles/swiplobjs.dir/os/pl-files.c.o src/CMakeFiles/swiplobjs.dir/os/pl-glob.c.o src/CMakeFiles/swiplobjs.dir/os/pl-os.c.o src/CMakeFiles/swiplobjs.dir/os/pl-stream.c.o src/CMakeFiles/swiplobjs.dir/os/pl-string.c.o src/CMakeFiles/swiplobjs.dir/os/pl-table.c.o src/CMakeFiles/swiplobjs.dir/os/pl-text.c.o src/CMakeFiles/swiplobjs.dir/os/pl-utf8.c.o src/CMakeFiles/swiplobjs.dir/os/pl-fmt.c.o src/CMakeFiles/swiplobjs.dir/os/pl-dtoa.c.o src/CMakeFiles/swiplobjs.dir/os/pl-option.c.o src/CMakeFiles/swiplobjs.dir/os/pl-cstack.c.o src/CMakeFiles/swiplobjs.dir/os/pl-codelist.c.o src/CMakeFiles/swiplobjs.dir/os/pl-prologflag.c.o src/CMakeFiles/swiplobjs.dir/os/pl-tai.c.o src/CMakeFiles/swiplobjs.dir/os/pl-locale.c.o src/CMakeFiles/swiplobjs.dir/os/pl-apple.c.o src/CMakeFiles/swiplobjs.dir/libtai/caltime_utc.c.o src/CMakeFiles/swiplobjs.dir/libtai/caltime_tai.c.o src/CMakeFiles/swiplobjs.dir/libtai/leapsecs_sub.c.o src/CMakeFiles/swiplobjs.dir/libtai/leapsecs_add.c.o src/CMakeFiles/swiplobjs.dir/libtai/caldate_fmjd.c.o src/CMakeFiles/swiplobjs.dir/libtai/caldate_mjd.c.o src/CMakeFiles/swiplobjs.dir/libtai/leapsecs_init.c.o src/CMakeFiles/swiplobjs.dir/libtai/leapsecs_read.c.o src/CMakeFiles/swiplobjs.dir/libtai/tai_pack.c.o src/CMakeFiles/swiplobjs.dir/libtai/tai_unpack.c.o src/CMakeFiles/swiplobjs.dir/minizip/zip.c.o src/CMakeFiles/swiplobjs.dir/minizip/unzip.c.o src/CMakeFiles/swiplobjs.dir/minizip/ioapi.c.o  -Wl,-rpath,:::::::::::::::::::::::::::::::::::::  -lcurses  -lform  /lib/libgmp.so  /usr/lib/libz.so  -ldl  -lm  -lrt && :
/usr/sbin/ld: /lib/libgmp.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status

I do have the 32 bit version of gmp installed:

lib32-gmp /usr/
lib32-gmp /usr/lib32/
lib32-gmp /usr/lib32/gmp/
lib32-gmp /usr/lib32/gmp/gmp.h
lib32-gmp /usr/lib32/gmp/gmpxx.h
lib32-gmp /usr/lib32/libgmp.so
lib32-gmp /usr/lib32/libgmp.so.10
lib32-gmp /usr/lib32/libgmp.so.10.4.1
lib32-gmp /usr/lib32/libgmpxx.so
lib32-gmp /usr/lib32/libgmpxx.so.4
lib32-gmp /usr/lib32/libgmpxx.so.4.6.1
lib32-gmp /usr/lib32/pkgconfig/
lib32-gmp /usr/lib32/pkgconfig/gmp.pc
lib32-gmp /usr/lib32/pkgconfig/gmpxx.pc

Not that likely as I only added an if(EMSCRPTEN) section to FindGMP.cmake. There could be the clue though as I still do not understand why this section is needed and why find_library() doesn’t do the job itself. Seems something is fishy with FindGMP.cmake :frowning:

I tried -DUSE_GMP=off to see what would happen, and libz has the same problem:

swiplobjs.dir/minizip/ioapi.c.o  -Wl,-rpath,:::::::::::::::::::::::::::::::::::::  -lcurses  -lform  /usr/lib/libz.so  -ldl  -lm  -lrt && :
/usr/sbin/ld: /usr/lib/libz.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
[...]

it is picking the 64 bit version in /usr/lib instead of the 32 bit version in /usr/lib32. No clue why. Seems the problem is more than just FindGMP.cmake.