Bug #15793 Linker errors when trying to build
Submitted: 15 Dec 2005 21:53 Modified: 20 Jan 2006 12:09
Reporter: Matt Lawrence Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.16 OS:Solaris (Solaris 9)
Assigned to: CPU Architecture:Any

[15 Dec 2005 21:53] Matt Lawrence
Description:
When attempting to compile (from the source tarball on this site), I get the following error:

Making all in extra
if gcc -DHAVE_CONFIG_H -I. -I. -I.. -I../include -I../include  -I../sql     -O3 -DDBUG_OFF -O3   -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T -MT comp_err.o -MD -MP -MF ".deps/comp_err.Tpo" -c -o comp_err.o comp_err.c; \
then mv -f ".deps/comp_err.Tpo" ".deps/comp_err.Po"; else rm -f ".deps/comp_err.Tpo"; exit 1; fi
/bin/bash ../libtool --preserve-dup-deps --mode=link gcc  -O3 -DDBUG_OFF -O3   -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T    -o comp_err  comp_err.o -all-static ../mysys/libmysys.a  ../dbug/libdbug.a ../strings/libmystrings.a -lpthread -lthread -lposix4 -lcrypt -lgen -lsocket -lnsl -lm  -lpthread -lthread
mkdir .libs
gcc -O3 -DDBUG_OFF -O3 -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T -o comp_err comp_err.o -static  ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread -lthread -lposix4 -lcrypt -lgen -lsocket -lnsl -lm -lpthread -lthread
ld: fatal: library -lpthread: not found
ld: fatal: library -lthread: not found
ld: fatal: library -lposix4: not found
ld: fatal: library -lpthread: not found
ld: fatal: library -lthread: not found
ld: fatal: File processing errors. No output written to comp_err
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `comp_err'
Current working directory /export/home/test/mysql-5.0.16/extra
*** Error code 1
make: Fatal error: Command failed for target `all-recursive'
Current working directory /export/home/test/mysql-5.0.16
*** Error code 1
make: Fatal error: Command failed for target `all'

How to repeat:
Here's the configure command that I used:

CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static -enable-thread-safe-client --without-server --with-low-memory --enable-thread-safe-client --without-server

#gcc -v
Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.9/3.4.0/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.4.0

#automake --version
automake (GNU automake) 1.7
Written by Tom Tromey <tromey@redhat.com>.
[19 Dec 2005 13:19] Valeriy Kravchuk
Thank you for a problem report. Verified just as described:

CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/users/vkravchuk/dbs/5.0-butch --enable-assembler --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-thread-safe-client --without-server --with-low-memory

Then make gives:

/bin/bash ../libtool --preserve-dup-deps --mode=link gcc  -O3 -DDBUG_OFF -O3   -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T   -o comp_err  comp_err.o -all-static ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread -lthread -lposix4 -lcrypt -lgen -lsocket -lnsl -lm  -lpthread -lthread
mkdir .libs
gcc -O3 -DDBUG_OFF -O3 -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T -o comp_err comp_err.o -static  ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread -lthread -lposix4 -lcrypt -lgen -lsocket -lnsl -lm -lpthread -lthread
ld: fatal: library -lpthread: not found
ld: fatal: library -lthread: not found
ld: fatal: library -lposix4: not found
ld: fatal: library -lpthread: not found
ld: fatal: library -lthread: not found
ld: fatal: File processing errors. No output written to comp_err
collect2: ld returned 1 exit status
make[2]: *** [comp_err] Error 1
make[2]: Leaving directory `/users/vkravchuk/mysql-5.0.16/extra'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/users/vkravchuk/mysql-5.0.16'
make: *** [all] Error 2

bash-2.05$ gcc -v
Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.9/3.4.2/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/l
d --disable-nls
Thread model: posix
gcc version 3.4.2
bash-2.05$ uname -a
SunOS butch 5.9 Generic_118558-09 sun4u sparc SUNW,UltraAX-i2

But I think that a real problem is your configure settings, which looks a little weird for me. Please, describe, what is the exact build requirements you are trying to achieve?

Note, that the following simple configure:

CC=cc-5.0 CXX=CC ASFLAGS=-xarch=v9 CFLAGS="-xO3 -Xa -xstrconst -mt -D_FORTEC_ -xarch=v9" CXXFLAGS="-xO3 -noex -mt -D_FORTEC_ -xarch=v9" LDFLAGS=-xarch=v9 ./configure --prefix=/users/vkravchuk/dbs/5.0-butch --with-extra-charsets=complex

gave me a working MySQL 5.0.16 server and client on this platform.
[19 Dec 2005 15:25] Matt Lawrence
All I'm trying to do is to build the client shared objects (libmysqlclient.so, libmysqlclient_r.so). Most of the stuff from the configure command is just from the INSTALL-SOURCE file that came with the tarball.
[20 Dec 2005 12:07] Valeriy Kravchuk
Please, try the following configure to build just shared libraries:

./configure \
--without-server \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--libexecdir=/usr/local/mysql/bin \
--with-extra-charsets=complex \
--enable-thread-safe-client \
--enable-local-infile \
--with-named-z-libs=no \
--enable-shared \
--with-zlib-dir=bundled \
--with-big-tables \
--with-readline \
--with-archive-storage-engine \
--with-innodb 

You can surely change the following options:

--prefix=/usr/local/mysql
--localstatedir=/usr/local/mysql/data
--libexecdir=/usr/local/mysql/bin

to a more suitable ones. The shared libs should end up in libmysql/.libs and libmysql_r/.libs (libmysqlclient.so).

Inform about the results.
[20 Dec 2005 15:23] Matt Lawrence
Alright, I gave that a try, and it now fails on mysqld.cc with the following error:

Making all in share
if g++ -DMYSQL_SERVER  -DDEFAULT_MYSQL_HOME="\"/home/test/mysql\""  -DDATADIR="\"/home/test/mysql/data\""  -DSHAREDIR="\"/home/test/mysql/share/mysql\""  -DHAVE_CONFIG_H -I. -I. -I.. -I../zlib  -I../innobase/include   -I../include -I../include  -I../regex -I.        -O3 -DDBUG_OFF    -fno-implicit-templates -fno-exceptions -fno-rtti -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T -MT mysqld.o -MD -MP -MF ".deps/mysqld.Tpo" -c -o mysqld.o mysqld.cc; \
then mv -f ".deps/mysqld.Tpo" ".deps/mysqld.Po"; else rm -f ".deps/mysqld.Tpo"; exit 1; fi
mysqld.cc:5891: error: an array reference cannot appear in a constant-expression
mysqld.cc:5892: error: an array reference cannot appear in a constant-expression
mysqld.cc:5893: error: an array reference cannot appear in a constant-expression
...
mysqld.cc:5990: error: an array reference cannot appear in a constant-expression
*** Error code 1
make: Fatal error: Command failed for target `mysqld.o'
Current working directory /export/home/test/mysql-5.0.16/sql
*** Error code 1
make: Fatal error: Command failed for target `all-recursive'
Current working directory /export/home/test/mysql-5.0.16/sql
*** Error code 1
make: Fatal error: Command failed for target `all'
Current working directory /export/home/test/mysql-5.0.16/sql
*** Error code 1
make: Fatal error: Command failed for target `all-recursive'
Current working directory /export/home/test/mysql-5.0.16
*** Error code 1
make: Fatal error: Command failed for target `all'

I cut out some of the array reference errors, because they were happening on pretty much every line in between 5891 and 5990. I can include the rest of the list if you'd like.
[20 Dec 2005 19:12] Matt Lawrence
Alright, I was able to get the shared objects to compile properly by just going into the libmysql/libmysql_r folders and typing make.
[21 Dec 2005 11:50] Valeriy Kravchuk
So, can we close this bug report as "Not a bug" now?
[17 Jan 2006 17:13] Peter Wood
Just wanted to note that I, too, am experiencing the 'mysqld.cc:5990: error: an array reference cannot appear in a constant-expression' error when trying to compile MySQL on my system as well. Here are my stats:

uname -a
SunOS xxxxxx 5.9 Generic_118558-19 sun4u sparc SUNW,Ultra-250

gcc -v
Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.9/3.4.0/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.4.0

MySQL version: 5.0.18, source tarball downloaded from dev.mysql.com.

I would still consider it to be a bug, because the code cannot compile properly out-of-the-box with a simple ./configure; make.
[17 Jan 2006 17:17] Peter Wood
I did try Matt Lawrence's suggestion to go into libmysql and libmysql_r and run a make. The make in those directories was successful; however, when I backed up one directory and ran make, the make still failed with the same errors:

--snip--
Making all in share
if g++ -DMYSQL_SERVER  -DDEFAULT_MYSQL_HOME="\"/mysql\""  -DDATADIR="\"/mysql/var\""  -DSHAREDIR="\"/mysql/share/mysql\""  -DHAVE_CONFIG_H -I. -I. -I.. -I../zlib  -I../innobase/include   -I../include -I../include  -I../regex -I.        -O3 -DDBUG_OFF    -fno-implicit-templates -fno-exceptions -fno-rtti -D_FILE_OFFSET_BITS=64 -DHAVE_RWLOCK_T -MT mysqld.o -MD -MP -MF ".deps/mysqld.Tpo" -c -o mysqld.o mysqld.cc; \
then mv -f ".deps/mysqld.Tpo" ".deps/mysqld.Po"; else rm -f ".deps/mysqld.Tpo"; exit 1; fi
mysqld.cc:5902: error: an array reference cannot appear in a constant-expression
--snip--
mysqld.cc:6001: error: an array reference cannot appear in a constant-expression
*** Error code 1
make: Fatal error: Command failed for target `mysqld.o'
Current working directory /opt/working/mysql-5.0.18/sql
*** Error code 1
make: Fatal error: Command failed for target `all-recursive'
Current working directory /opt/working/mysql-5.0.18/sql
*** Error code 1
make: Fatal error: Command failed for target `all'
Current working directory /opt/working/mysql-5.0.18/sql
*** Error code 1
make: Fatal error: Command failed for target `all-recursive'
Current working directory /opt/working/mysql-5.0.18
*** Error code 1
make: Fatal error: Command failed for target `all'

So... there still seems to be a bug here.
[20 Jan 2006 12:09] Sergei Golubchik
I don't know why gcc 3.4.0 does not understand that syntax (the expression offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BACKUP_TABLE])), but gcc 3.4.1 to gcc 3.4.4 have no problems with it (as well as older gcc 2.95.x, gcc.3.x and newer gcc 4.x).

Perhaps it was a bug in gcc 3.4.0 or a limitation that was lifted. In any case your best option would be upgrading gcc.