Bug 33 - Compilation abort with "undefined reference to `gmp_randinit_mt'" on Centos/Redhat
: Compilation abort with "undefined reference to `gmp_randinit_mt'" on Centos/R...
Status: RESOLVED FIXED
Product: SWI-Prolog
Classification: Unclassified
Component: core
: unspecified
: PC Linux
: Highest normal
Assigned To: Jan Wielemaker
:
:
:
  Show dependency treegraph
 
Reported: 2012-04-15 15:08 CEST by Joachim Neubert
Modified: 2012-08-13 16:49 CEST (History)
0 users

See Also:


Attachments
Patch for gmp_randinit_mt() check (488 bytes, patch)
2012-08-10 18:58 CEST, Joachim Katzer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Neubert 2012-04-15 15:08:40 CEST
On two different Centos 5.8 systems (32 as well as 64 bit) I get an error when
compiling the git version (7969ba656708e340dcfcfca2d5a12b53243e453e) of SWI
prolog:

...
gcc44 -c -I. -I../src -I../src/rc -Wall -O2  -fno-strict-aliasing -pthread
-fPIC  pl-arith.c -o pl-arith.o
pl-arith.c: In function ‘init_random’:
pl-arith.c:2899: warning: implicit declaration of function ‘gmp_randinit_mt’
pl-arith.c: In function ‘popForMark’:
pl-arith.c:646: warning: ‘w’ may be used uninitialized in this function
...
gcc44 -shared -O2 -o ../lib/x86_64-linux/libswipl.so.6.0.2
-Wl,-soname=libswipl.so.6.0.2 \
                        pl-atom.o pl-wam.o pl-arith.o pl-bag.o pl-error.o
pl-comp.o pl-rc.o pl-dwim.o pl-ext.o pl-flag.o pl-funct.o pl-gc.o pl-privitf.o
pl-list.o pl-load.o pl-modul.o pl-op.o pl-prims.o pl-pro.o pl-proc.o pl-prof.o
pl-read.o pl-rec.o pl-setup.o pl-sys.o pl-trace.o pl-util.o pl-wic.o pl-write.o
pl-term.o pl-thread.o pl-xterm.o pl-beos.o pl-attvar.o pl-gvar.o pl-btree.o
pl-main.o pl-gmp.o pl-segstack.o pl-hash.o pl-version.o pl-codetable.o
pl-supervisor.o pl-dbref.o pl-termhash.o pl-variant.o pl-copyterm.o pl-debug.o
os/pl-buffer.o os/pl-ctype.o os/pl-file.o os/pl-files.o os/pl-glob.o os/pl-os.o
os/pl-stream.o os/pl-string.o os/pl-table.o os/pl-text.o os/pl-utf8.o
os/pl-fmt.o os/pl-dtoa.o os/pl-option.o os/pl-cstack.o os/pl-codelist.o
os/pl-prologflag.o os/pl-rl.o os/pl-tai.o rc/access.o rc/build.o rc/html.o
rc/util.o libtai/caltime_utc.o libtai/caltime_tai.o libtai/leapsecs_sub.o
libtai/leapsecs_add.o libtai/caldate_fmjd.o libtai/caldate_mjd.o
libtai/leapsecs_init.o libtai/leapsecs_read.o libtai/tai_pack.o
libtai/tai_unpack.o  -rdynamic -O2 -pthread
-Wl,-rpath=/lib/swipl-6.0.2/lib/x86_64-linux:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 -lgmp -lrt -lreadline -lncursesw -lm -lrt -ldl
( cd ../lib/x86_64-linux && rm -f libswipl.so && ln -s libswipl.so.6.0.2
libswipl.so )
gcc44 -c -I. -I../src -I../src/rc -Wall -O2  -fno-strict-aliasing -pthread
-fPIC  pl-extend.c -o pl-extend.o
gcc44 -rdynamic -O2 -pthread
-Wl,-rpath=/lib/swipl-6.0.2/lib/x86_64-linux:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  -o swipl pl-extend.o -L../lib/x86_64-linux -lswipl
../lib/x86_64-linux/libswipl.so: undefined reference to `gmp_randinit_mt'
collect2: ld returned 1 exit status
make[1]: *** [swipl] Error 1
make[1]: Leaving directory `/usr/local/src/git/pl/src'
make: *** [lite] Error 2

The adaptions of the build file are:

# diff build.templ build
19c19
< PREFIX=$HOME
---
> #PREFIX=$HOME
46a47
> export CC=gcc44 CXX=g++44
156c157
< # export RPATH_RESERVE=70
---
> export RPATH_RESERVE=70

The installed versions are:

# rpm -aq|egrep "(gcc44|gmp)"
gmp-4.1.4-10.el5
gcc44-4.4.6-3.el5.1
gmp-devel-4.1.4-10.el5
gmp-devel-4.1.4-10.el5
gcc44-c++-4.4.6-3.el5.1
gmp-4.1.4-10.el5

Same result with SElinux disabled.
Comment 1 Jan Wielemaker 2012-04-15 17:14:46 CEST
Seems that this function was introduced in gmp 4.2.0.  Added a configure
test.  See commit fb745832eb0cd60cf886c768499cae6202aaf1d1 in pl-devel.git.
http://www.swi-prolog.org/git/pl-devel.git/commit/fb745832eb0cd60cf886c768499cae6202aaf1d1

You can either upgrade libgmp or apply this patch to the version you want
to compile.

   Cheers --- Jan
Comment 2 Joachim Neubert 2012-04-16 07:59:30 CEST
Thank you very much for the quick fix! I could apply the patch, but
unfortunately the configure test for HAVE_GMP_RANDINIT_MT evaluates to true (on
my Centos 64 system), so it worked only after I reverted configure.in.
Comment 3 Jan Wielemaker 2012-04-16 08:56:56 CEST
Should be better now.  Stupid typo

   --- Jan
Comment 4 Joachim Neubert 2012-04-17 09:27:38 CEST
The patched version

diff --git a/src/configure.in b/src/configure.in
index 6e2e8d3..8d513a7 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1237,6 +1237,18 @@ if test "$configgmp" = "yes"; then
                    LIBS="-lgmp $LIBS",
                    WARN_NO_GMP=yes)
   fi
+
+  AC_MSG_CHECKING("For gmp_randinit_mt()");
+  AC_TRY_COMPILE(
+      [#include <gmp.h>
+      ],
+      [ gmp_randstate_t state;
+       gmp_randinit_mt(&state);
+      ],
+      AC_MSG_RESULT(yes)
+      AC_DEFINE(HAVE_GMP_RANDINIT_MT, 1,
+               [ Define you you have gmp_randinit_mt (gmp > 4.2.0) ]),
+      AC_MSG_RESULT(no))
 fi

 dnl Setup DMALLOC


still evaluates to true.
Comment 5 Joachim Katzer 2012-08-10 18:58:02 CEST
Created attachment 19 [details]
Patch for gmp_randinit_mt() check

The configure check for gmp_randinit_mt() is still wrong in GIT.

I suggest the following changes:
It should check for gmp_randinit_mt() instead of gmp_randinit_default()
(typo?),
and the macro AC_TRY_LINK instead of AC_TRY_COMPILE should be used because the
error is reported by linker, not compiler.
Comment 6 Jan Wielemaker 2012-08-13 16:49:08 CEST
(In reply to comment #5)
> Created attachment 19 [details]
> Patch for gmp_randinit_mt() check
> 
> The configure check for gmp_randinit_mt() is still wrong in GIT.
> 
> I suggest the following changes:
> It should check for gmp_randinit_mt() instead of gmp_randinit_default()
> (typo?),
> and the macro AC_TRY_LINK instead of AC_TRY_COMPILE should be used because the
> error is reported by linker, not compiler.

The first was already fixed in e17fff73785d6d9d577703fcf6469a57a31db851.  
Now changed AC_TRY_COMPILE into AC_TRY_LINK.  Thanks.

       --- Jan