List:Internals« Previous MessageNext Message »
From:Vasil Dimov Date:May 30 2007 7:27am
Subject:MySQL-5.1 does not compile with gcc 4.2.0
View as plain text  
Hi,

### get the latest BK source

mysql-5.1$ bkf pull
INFO-generating patch, please wait...
INFO-nothing to send.
mysql-5.1$ 

### configure

mysql-5.1$ ./BUILD/autorun.sh
mysql-5.1$ ./configure

### try to build

mysql-5.1$ gmake
...
gmake  all-am
gmake[3]: Entering directory `/mnt/mnt0001/mysql-5.1/client'
if g++ -DUNDEF_THREADS_HACK -DDEFAULT_MYSQL_HOME="\"/usr/local\""
-DDATADIR="\"/usr/local/var\"" -I. -I. -I.. -I../include -I../include -I../regex     -O3 
  -fno-implicit-templates -fno-exceptions -fno-rtti -DMYSQLD_NET_RETRY_COUNT=1000000 -MT
mysql.o -MD -MP -MF ".deps/mysql.Tpo" -c -o mysql.o mysql.cc; \
        then mv -f ".deps/mysql.Tpo" ".deps/mysql.Po"; else rm -f ".deps/mysql.Tpo"; exit
1; fi
mysql.cc: In function 'void print_table_data(MYSQL_RES*)':
mysql.cc:2361: error: 'max' was not declared in this scope
mysql.cc:2363: error: 'max' was not declared in this scope
mysql.cc:2384: error: 'min' was not declared in this scope
gmake[3]: *** [mysql.o] Error 1
gmake[3]: Leaving directory `/mnt/mnt0001/mysql-5.1/client'
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory `/mnt/mnt0001/mysql-5.1/client'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/mnt/mnt0001/mysql-5.1'
gmake: *** [all] Error 2
mysql-5.1$ 

I applied this patch to isolate the problem:

--- include/my_global.h.orig    Wed May 30 10:14:55 2007
+++ include/my_global.h Wed May 30 10:16:02 2007
@@ -1488,7 +1488,17 @@
  *  Include standard definitions of operator new and delete.
  */
 #ifdef __cplusplus
+#if defined(max)
+#warning max is defined before #include <new>
+#else
+#warning max is not defined before #include <new>
+#endif
 #include <new>
+#if defined(max)
+#warning max is defined before #include <new>
+#else
+#warning max is not defined before #include <new>
+#endif
 #endif
 #else
 /*

and got

...
gmake[3]: Entering directory `/mnt/mnt0001/mysql-5.1/client'
if g++ -DUNDEF_THREADS_HACK -DDEFAULT_MYSQL_HOME="\"/usr/local\""
-DDATADIR="\"/usr/local/var\"" -I. -I. -I.. -I../include -I../include -I../regex     -O3 
  -fno-implicit-templates -fno-exceptions -fno-rtti -DMYSQLD_NET_RETRY_COUNT=1000000 -MT
mysql.o -MD -MP -MF ".deps/mysql.Tpo" -c -o mysql.o mysql.cc; \
        then mv -f ".deps/mysql.Tpo" ".deps/mysql.Po"; else rm -f ".deps/mysql.Tpo"; exit
1; fi
In file included from client_priv.h:18,
                 from mysql.cc:31:
../include/my_global.h:1492:2: warning: #warning max is defined before #include
<new>
../include/my_global.h:1500:2: warning: #warning max is not defined before #include
<new>
mysql.cc: In function 'void print_table_data(MYSQL_RES*)':
mysql.cc:2361: error: 'max' was not declared in this scope
mysql.cc:2363: error: 'max' was not declared in this scope
mysql.cc:2384: error: 'min' was not declared in this scope
gmake[3]: *** [mysql.o] Error 1
gmake[3]: Leaving directory `/mnt/mnt0001/mysql-5.1/client'
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory `/mnt/mnt0001/mysql-5.1/client'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/mnt/mnt0001/mysql-5.1'
gmake: *** [all] Error 2
mysql-5.1$ 

### platform and compiler details

$ gcc -v
Using built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.0 20070514 [FreeBSD]
$

$ grep -n -B2 'undef max' /usr/include/c++/4.2/bits/c++config.h 
202-// For example, <windows.h> is known to #define min and max as macros...
203-#undef min
204:#undef max

ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.2.0/gcc-g++-4.2.0.tar.bz2
indeed contains this code in
gcc-4.2.0/libstdc++-v3/include/bits/c++config
so I guess it is not FreeBSD related, but rather gcc 4.2.0 related
(maybe also in earlier versions).

One solution would be to s/max/MAX/ everywhere in the code.
(this way it will also be clear that it is a macro, not a function, and
may have unexpected results if called like MAX(a++, b)).

Hope that helps.

-- 
Vasil Dimov
moc.elcaro@stripped        Software Developer @ Oracle/Innobase Oy
gro.DSBeerF@dv                Committer @ FreeBSD.org
gro.d5v@dv                    Home @ Sofia, Bulgaria

Attachment: [application/pgp-signature]
Thread
MySQL-5.1 does not compile with gcc 4.2.0Vasil Dimov30 May
  • Re: MySQL-5.1 does not compile with gcc 4.2.0Vasil Dimov30 May
  • Re: MySQL-5.1 does not compile with gcc 4.2.0Vasil Dimov11 Jun