Latest Tweets

Compiling Xmgr on a Debian Etch box throws an “undeclared log2() function” error.

The issue

 Compiling the xmgr 4.1.2 sources on a box running Debian Etch, a compilation error appears:

gcc -O2 -Wall -pedantic -m486 -malign-double -I.. -I. -DGR_HOME=\”/usr/local/xmgr\” -DPRINT_CMD=\”‘lpr’\” -c -o pars.o pars.c
pars.yacc:4140: error: ‘log2’ undeclared here (not in a function)
make[1]: *** [pars.o] Error 1

Apparently, the log2() function is not declared and the compilation process fails. This does not happen on modern GNU/Linux Debian distros.

log2() does exist.

the log2() function is only defined in the C99 standard, according to this: http://stackoverflow.com/questions/758001/log2-not-found-in-my-math-h. Having a look inside the /usr/include directory, we can find the function correctly declared and defined here:

grep -R "log2" *
bits/mathcalls.h:__MATHCALL (log2,, (_Mdouble_ __x));
...
bits/mathinline.h:__inline_mathop_declNP (log2, "fld1; fxch; fyl2x", "0" (__x) : "st(1)")

Reading the /usr/include/bits/mathcalls.h header file, we find when and where the log2() function is already declared:

139 #ifdef __USE_ISOC99
140 __BEGIN_NAMESPACE_C99
141 /* Compute base-2 exponential of X.  */
142 __MATHCALL (exp2,, (_Mdouble_ __x));
143 
144 /* Compute base-2 logarithm of X.  */
145 __MATHCALL (log2,, (_Mdouble_ __x));
146 __END_NAMESPACE_C99
147 #endif

In order to force the compiler to add the conditional constant __USE_ISOC99, we have to compile the Xmgr sources adding the -std=c99 flag. By doing this, the conditional compilation process will certainly take this branch (see lines 139, 140 and 147, and therefore the log2() function will be declared:

cd xmgr-4.1.2/
CFLAGS="-std=c99" ./configure

However, the “configure” script for this xmgr version does not take into account the CFLAGS variable. Instead, we have to alter the CFLAGS0 variable directly inside the Make.conf file, as a result of running the ./configure script:

./configure 
....
vi Make.conf
...
64 # C flags
65 CFLAGS0=-O2 -Wall -pedantic -m486 -malign-double -std=c99

After doing this, we can run the compilation process by typing “make“. This time, the Xmgr will be compiled with no issues at all.