Bug #30866 Fail to compile
Submitted: 6 Sep 2007 15:43 Modified: 23 Nov 2007 13:28
Reporter: Piotr Klimczak Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:6.0.3 downloaded by BK 06:09:2007 D:M:Y, 5.1 BK, 5.0 BK, 4.1 BK OS:Linux (openSUSE 10.3 Beta3)
Assigned to: CPU Architecture:Any
Tags: Contribution

[6 Sep 2007 15:43] Piotr Klimczak
Description:
make[2]: Wejście do katalogu `/local/FedEx/Server/mysql-6.0-falcon/client'
g++ -DUNDEF_THREADS_HACK -DDEFAULT_MYSQL_HOME="\"/local/Main/Builded/mysql6/\"" -DDATADIR="\"/local/Main/Builded/mysql6//var\"" -I. -I../include -I../include -I../include -I../regex     -g -DSAFE_MUTEX -DSAFEMALLOC    -fno-implicit-templates -fno-exceptions -fno-rtti -MT mysql.o -MD -MP -MF .deps/mysql.Tpo -c -o mysql.o mysql.cc
mysql.cc: In function 'void print_table_data(MYSQL_RES*)':
mysql.cc:2401: error: 'max' was not declared in this scope
mysql.cc:2403: error: 'max' was not declared in this scope
mysql.cc:2424: error: 'min' was not declared in this scope
make[2]: *** [mysql.o] Błąd 1

How to repeat:
just compile

Suggested fix:
IN /include/my_global.h 

 /* Define some useful general macros */
-#if !defined(max)
-#define max(a, b)	((a) > (b) ? (a) : (b))
-#define min(a, b)	((a) < (b) ? (a) : (b))
+#if !defined(mysql_max)
+#define mysql_max(a, b)      ((a) > (b) ? (a) : (b))
+#define mysql_min(a, b)      ((a) < (b) ? (a) : (b))
+static __inline long min( long a, long b ) { return ( ( a < b ) ? a : b ); }
+static __inline long max( long a, long b ) { return ( ( a > b ) ? a : b ); }
 #endif

also some changes in /client/mysql.cc and other files using max()/min() to mysql_min()/mysql_max()
[6 Sep 2007 22:01] Piotr Klimczak
It is useful to perform changes from min()/max() to mysql_min()/mysql_max() by using those command lines from mysql source root dir...
After that everything should work fine:

find . -type f -exec sed -i -e 's|min(|mysql_min(|g' -e 's|max(|mysql_max(|g' '{}' ';' 
find . -type f -exec sed -i -e 's|mysql_mysql_min(|mysql_min(|g' -e 's|mysql_mysql_max(|mysql_max(|g' '{}' ';' 
find . -type f -exec sed -i -e 's|xmysql_min(|xmin(|g' -e 's|xmysql_max(|xmax(|g' '{}' ';'
find . -type f -exec sed -i -e 's|ymysql_min(|ymin(|g' -e 's|ymysql_max(|ymax(|g' '{}' ';'
find . -type f -exec sed -i -e 's|Item_sum_mysql_min(|Item_sum_min(|g' -e 's|Item_sum_mysql_max(|Item_sum_max(|g' '{}' ';'
find . -type f -exec sed -i -e 's|Item_func_min_mysql_max(|Item_func_min_max(|g' '{}' ';'
find . -type f -exec sed -i -e 's|Item_func_mysql_min(|Item_func_min(|g' -e 's|Item_func_mysql_max(|Item_func_max(|g' '{}' ';'
find . -type f -exec sed -i -e 's|fmysql_max(|fmax(|g' -e 's|fmysql_min(|fmin(|g' '{}' ';'
find . -type f -exec sed -i -e 's|have_mysql_max(|have_max(|g' -e 's|have_mysql_min(|have_min(|g' '{}' ';'
find . -type f -exec sed -i -e 's|s_mysql_max(|s_max(|g' -e 's|s_mysql_min(|s_min(|g' '{}' ';'
[7 Sep 2007 6:50] Sveta Smirnova
Thank you for the report.

Please provide exact steps how you compiling MySQL. I mean sequence of autotools call and exact configure line.
[7 Sep 2007 9:42] Piotr Klimczak
I'm using (gcc -v):
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2 --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=i586-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)

0. su mysql
1. MySQL downloaded: 6.0.3 06:09:2007 D:M:Y using BK client
2. bkf clone bk://mysql.bkbits.net/mysql-6.0-falcon mysql6
3. cd mysql6
4. ./BUILD/compile-pentium-debug-falcon
OR
4. ./configure --prefix=/local/Main/Builded/mysql6/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-debug=full --with-plugins=falcon,innobase,myisammrg,myisam,federated,csv,archive,heap --with-partition --enable-local-infile
5. make- it fails as described error appears.
6. su -c "make install"

What i've done to make the database to work stable is:
1. cd YSQL_SOURCE_ROOT_DIR/include/my_global.h and change:

 /* Define some useful general macros */
-#if !defined(max)
-#define max(a, b)	((a) > (b) ? (a) : (b))
-#define min(a, b)	((a) < (b) ? (a) : (b))
+#if !defined(mysql_max)
+#define mysql_max(a, b)      ((a) > (b) ? (a) : (b))
+#define mysql_min(a, b)      ((a) < (b) ? (a) : (b))
+static __inline long min( long a, long b ) { return ( ( a < b ) ? a :
b ); }
+static __inline long max( long a, long b ) { return ( ( a > b ) ? a :
b ); }
 #endif

2. cd MYSQL_SOURCE_ROOT_DIR/client

3.
# find . -type f -exec sed -i -e 's|)min(|)mysql_min(|g' -e 's|)max(|)mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|>min(|>mysql_min(|g' -e 's|>max(|>mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|<min(|<mysql_min(|g' -e 's|<max(|<mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|,min(|,mysql_min(|g' -e 's|,max(|,mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|\[min(|\[mysql_min(|g' -e 's|\[max(|\[mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|(min(|(mysql_min(|g' -e 's|(max(|(mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|+min(|+mysql_min(|g' -e 's|+max(|+mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|-min(|-mysql_min(|g' -e 's|-max(|-mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's| min(| mysql_min(|g' -e 's| max(| mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|=min(|=mysql_min(|g' -e 's|=max(|=mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|*min(|*mysql_min(|g' -e 's|*max(|*mysql_max(|g' '{}' ';' 

4. cd MYSQL_SOURCE_ROOT_DIR/sql

5.
# find . -type f -exec sed -i -e 's|)min(|)mysql_min(|g' -e 's|)max(|)mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|>min(|>mysql_min(|g' -e 's|>max(|>mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|<min(|<mysql_min(|g' -e 's|<max(|<mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|,min(|,mysql_min(|g' -e 's|,max(|,mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|\[min(|\[mysql_min(|g' -e 's|\[max(|\[mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|(min(|(mysql_min(|g' -e 's|(max(|(mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|+min(|+mysql_min(|g' -e 's|+max(|+mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|-min(|-mysql_min(|g' -e 's|-max(|-mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's| min(| mysql_min(|g' -e 's| max(| mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|=min(|=mysql_min(|g' -e 's|=max(|=mysql_max(|g' '{}' ';'
# find . -type f -exec sed -i -e 's|*min(|*mysql_min(|g' -e 's|*max(|*mysql_max(|g' '{}' ';' 

Those scripts have to be performed before configure script is builded and only on source files.
Then followed compile steps starting from 4th step.

Database is stable. No error logs in {HOST}.err after few hours of using on production server.

As i know this problem occurs when including header files in situations like this:
one.cc->one.h->two.h->one.h
where max()/min() is already defined, so max()/min() will not defined previously (but i'm not 100% sure about this explanation).

Hope it's helpful...

Best regards
Piotr Klimczak
[7 Sep 2007 11:23] Piotr Klimczak
More info:

SOFTWARE VERSIONS:

gmake -v => GNU Make 3.81
libtoolize --version => libtoolize (GNU libtool) 1.5.24
aclocal --version => aclocal (GNU automake) 1.10
autoheader --version => autoheader (GNU Autoconf) 2.61
automake --version => automake (GNU automake) 1.10
autoconf --version => autoconf (GNU Autoconf) 2.61

The ./BUILD/compile-pentium-debug produce:

+++ gmake -k maintainer-clean
gmake: *** Brak reguł do wykonania obiektu `maintainer-clean'.
+++ true
+++ /bin/rm -rf '*/.deps/*.P' configure config.cache 'storage/*/configure' 'storage/*/config.cache' autom4te.cache 'storage/*/autom4te.cache'
+++ path=./BUILD
+++ . ./BUILD/autorun.sh
++++ '[' -f /usr/bin/glibtoolize ']'
++++ LIBTOOLIZE=libtoolize
++++ aclocal
++++ autoheader
++++ libtoolize --automake --force
++++ automake --add-missing --force
configure.in:13: installing `./missing'
configure.in:13: installing `./install-sh'
BUILD/Makefile.am:69: `%'-style pattern rules are a GNU make extension
Docs/Makefile.am:69: `%'-style pattern rules are a GNU make extension
client/Makefile.am:122: `%'-style pattern rules are a GNU make extension
client/Makefile.am:82: compiling `mysqlslap.c' with per-target flags requires `AM_PROG_CC_C_O' in `configure.in'
client/Makefile.am: installing `./depcomp'
cmd-line-utils/Makefile.am:24: `%'-style pattern rules are a GNU make extension
cmd-line-utils/libedit/Makefile.am:100: `%'-style pattern rules are a GNU make extension
cmd-line-utils/readline/Makefile.am:37: `%'-style pattern rules are a GNU make extension
dbug/Makefile.am:65: `%'-style pattern rules are a GNU make extension
debian/Makefile.am:117: `%'-style pattern rules are a GNU make extension
extra/Makefile.am:54: `%'-style pattern rules are a GNU make extension
extra/yassl/src/Makefile.am:7: wildcard ../include/*.hpp: non-POSIX variable name
extra/yassl/src/Makefile.am:7: (probably a GNU make extension)
.....
.....
.....
zlib/Makefile.am:38: `%'-style pattern rules are a GNU make extension
++++ autoconf
+++ CC=gcc
+++ CFLAGS='-Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wunused-parameter  -DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS  -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX -D_DEBUG -DMEM_DEBUG'
+++ CXX=gcc
+++ CXXFLAGS='-Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti  -DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS  -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX -D_DEBUG -DMEM_DEBUG'
+++ CXXLDFLAGS=
+++ ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-debug=full --enable-local-infile
[7 Sep 2007 11:36] Sveta Smirnova
Thank you for the feedback.

I can not repeat error in my environment. Please upgrade aclocal and automake to version 1.9.5, try with it and say us result.
[7 Sep 2007 12:45] Piotr Klimczak
I can't upgrade it as my is newer than your... unless you mean to downgrade...

main 1.10 > 1.9.5 your

You should try again on newer environment as i doubt you mean you want me to downgrade main.
[7 Sep 2007 12:58] Sveta Smirnova
Thank you for the point =)

We'll try.
[9 Sep 2007 12:25] Christian Hammers
I can confirm this bug on a my system running the latest Debian unstable.
[25 Sep 2007 9:48] Sveta Smirnova
Thank you for the report.

Verified as described.

To repeat one should have all latest autotools including autoconf and libtool.
[2 Oct 2007 21:23] Christian Hammers
Ping!

MySQL-5.1 does not compile on openSUSE and Debian for a month now?! The problem still exists in 5.1.22-rc and I'm starting to wonder what a definition of "release candidate" this might be :-)

Apart from that I really want to upload 5.1 to Debian unstable before you declare it stable as our users surely find you a bug or two but as long as it's unbuildable there is no chance.

So please raise the severity of this bug a bit.

bye,

-christian-

For reference here the current output and my build environment:

if g++ -DUNDEF_THREADS_HACK -DDEFAULT_MYSQL_HOME="\"/usr\"" -DDATADIR="\"/var/lib/mysql\"" -I. -I. -I../include -I../include -I../include -I../regex     -O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti   -fno-implicit-templates -fno-exceptions -fno-rtti -MT sql_string.o -MD -MP -MF ".deps/sql_string.Tpo" -c -o sql_string.o sql_string.cc; \
        then mv -f ".deps/sql_string.Tpo" ".deps/sql_string.Po"; else rm -f ".deps/sql_string.Tpo"; exit 1; fi
mysql.cc: In function 'void print_table_data(MYSQL_RES*)':
mysql.cc:2401: error: 'max' was not declared in this scope
mysql.cc:2403: error: 'max' was not declared in this scope
mysql.cc:2424: error: 'min' was not declared in this scope
make[3]: *** [mysql.o] Fehler 1
make[3]: *** Warte auf noch nicht beendete Prozesse...
sql_string.cc: In member function 'int String::reserve(uint32, uint32)':
sql_string.cc:665: error: 'max' was not declared in this scope
sql_string.cc: In function 'int stringcmp(const String*, const String*)':
sql_string.cc:751: error: 'min' was not declared in this scope
sql_string.cc: In function 'String* copy_if_not_alloced(String*, String*, uint32)':
sql_string.cc:768: error: 'min' was not declared in this scope
make[3]: *** [sql_string.o] Fehler 1
make[3]: Leaving directory `/home/ch/debian/mysql/exp-5.1/mysql-dfsg-5.1-5.1.22rc/client'
make[2]: *** [all] Fehler 2
make[2]: Leaving directory `/home/ch/debian/mysql/exp-5.1/mysql-dfsg-5.1-5.1.22rc/client'
make[1]: *** [all-recursive] Fehler 1
make[1]: Leaving directory `/home/ch/debian/mysql/exp-5.1/mysql-dfsg-5.1-5.1.22rc'
make: *** [build-stamp] Fehler 2

Output from mysqlbug:

>C compiler:    gcc (GCC) 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)
>C++ compiler:  g++ (GCC) 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)
>Environment:
        <machine, os, target, libraries (multiple lines)>
System: Linux app109 2.6.22-2-amd64 #1 SMP Thu Aug 30 23:43:59 UTC 2007 x86_64 GNU/Linux

Some paths:  /usr/bin/perl /usr/bin/make /usr/lib/ccache//gcc /usr/lib/ccache//cc
GCC: Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/us
Thread model: posix
gcc version 4.2.1 (Debian 4.2.1-5)
Compilation info: CC='gcc'  CFLAGS='-O3 -DBIG_JOINS=1'  CXX='g++'  CXXFLAGS='-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti'  LDFLAGS=''  A
LIBC:
lrwxrwxrwx 1 root root 13 2007-09-28 19:32 /lib/libc.so.6 -> libc-2.6.1.so
-rwxr-xr-x 1 root root 1391960 2007-09-17 09:45 /lib/libc-2.6.1.so
-rw-r--r-- 1 root root 4308444 2007-09-17 09:45 /usr/lib/libc.a
-rw-r--r-- 1 root root 247 2007-09-17 09:28 /usr/lib/libc.so
-rw-r--r-- 1 root root 1587844 2007-08-22 17:41 /usr/lib/libc-client.a
lrwxrwxrwx 1 root root 23 2007-09-03 23:43 /usr/lib/libc-client.so -> libc-client.so.2006j2.0
lrwxrwxrwx 1 root root 23 2007-09-03 23:43 /usr/lib/libc-client.so.2006j2 -> libc-client.so.2006j2.0
-rw-r--r-- 1 root root 1124144 2007-08-22 17:41 /usr/lib/libc-client.so.2006j2.0
Configure command: ./configure '--build=x86_64-linux-gnu' '--host=x86_64-linux-gnu' '--prefix=/usr' '--exec-prefix=/usr' '--libexecdir=/usr/sbin' '--datadir=
[2 Oct 2007 21:26] Christian Hammers
(note that my above output was created with "make -j2" so it looks a bit garbled)
[2 Oct 2007 21:56] Christian Hammers
I can confirm that the Piotrs patches fix the problem. I build 5.1.22-rc and currently run the benchmark suite as little regression test.

bye,

-christian-
[4 Oct 2007 11:47] Sergei Golubchik
It was fixed with this changeset:

http://mysql.bkbits.net:8080/mysql-5.1/?PAGE=cset&REV=46dbec1c1lAGFuqFZQy58XVe4KSijg

Unfortunately, it didn't made into 5.1.22 release, which was cloned off on Aug 30.

But we should have a new 5.1 release soon.
[23 Nov 2007 13:28] Hartmut Holzgraefe
Duplicate of bug #28184