Bug #47360 Can't build universal x86_64/i386: Undefined symbols for architecture x86_64
Submitted: 16 Sep 2009 9:53 Modified: 16 Jan 2014 13:04
Reporter: Ryan Schmidt Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.1.38 OS:MacOS (10.6.1)
Assigned to: CPU Architecture:Any
Tags: regression, universal

[16 Sep 2009 9:53] Ryan Schmidt
Description:
I'm trying to compile an x86_64/i386 universal binary of MySQL 5.1.38 on Mac OS X 10.6.1 Snow Leopard and it fails as follows:

Undefined symbols for architecture x86_64:
  "_mysql_shutdown", referenced from:
      do_shutdown_server(st_command*)      in mysqltest.o
      _main in mysqltest.o
  "_strend", referenced from:
      convert_to_format_v1(char*) in mysqltest.o
      strip_surrounding(char*, char, char)in mysqltest.o
      end_of_word(char*) in mysqltest.o
      read_embedded_server_arguments(char const*)in mysqltest.o
      read_command(st_command**)      in mysqltest.o

and so forth (1500 additional lines of error follow -- I will attach the complete log).

A plain x86_64-only build of 5.1.38 works fine on the same system.

An x86_64/i386 universal build of 5.0.85 also works fine on the same system.

How to repeat:
1. On a 64-bit Intel Mac with Snow Leopard, install MacPorts 1.8.0 for Snow Leopard
2. In the Terminal, type "sudo port install mysql5-devel +universal"

This is how MacPorts performs the universal build:

DEBUG: Environment: CFLAGS='-O2 -fPIC -arch x86_64 -arch i386' CPPFLAGS='-I/opt/local/include' CXXFLAGS='-O2 -fPIC -arch x86_64 -arch i386' MACOSX_DEPLOYMENT_TARGET='10.6' CXX='/usr/bin/g++-4.2' F90FLAGS='-O2' LDFLAGS='-L/opt/local/lib -arch x86_64 -arch i386' OBJC='/usr/bin/gcc-4.2' FCFLAGS='-O2' INSTALL='/usr/bin/install -c' OBJCFLAGS='-O2 -arch x86_64 -arch i386' FFLAGS='-O2' CC='/usr/bin/gcc-4.2'
DEBUG: Assembled command: 'cd "/opt/local/var/macports/build/_Users_rschmidt_macports_dports_databases_mysql5-devel/work/mysql-5.1.38" && ./configure --prefix=/opt/local --disable-dependency-tracking --mandir=/opt/local/share/man --infodir=/opt/local/share/info --localstatedir=/opt/local/var/db/mysql5 --libdir=/opt/local/lib/mysql5 --bindir=/opt/local/lib/mysql5/bin --includedir=/opt/local/include/mysql5 --datadir=/opt/local/share/mysql5 --sysconfdir=/opt/local/etc/mysql5 --with-zlib-dir=/opt/local --with-ssl=/opt/local --with-extra-charsets=complex --with-unix-socket-path=/opt/local/var/run/mysql5/mysqld.sock --with-mysqld-user=mysql --without-docs --without-bench --with-partition --with-plugins=all --enable-thread-safe-client --without-readline --with-embedded-server --with-pic'
[16 Sep 2009 9:54] Ryan Schmidt
complete build output

Attachment: mysql5-5.1.38-universal.txt.bz2 (application/x-bzip2, text), 56.90 KiB.

[18 Sep 2009 16:37] Valeriy Kravchuk
On Mac OS X 10.5.x "single-platform" 5.1.38 binaries from MacPorts also builds OK, while +universal do NOT. The errors I've got were different though...
[30 Sep 2009 10:21] Geert Vanderkelen
Compiled 5.1.39 fine on MacOS X 10.6.1 (Latest XCode, No MacPorts). Slightly modified the build options, try and give us feed back whether it works on your install or not. Maybe with other options set, etc..

-Geert

(put following in a file named compile.sh and execute it in the source dir)

CFLAGS='-O2 -fPIC -arch x86_64 -arch i386'
CPPFLAGS='-I/opt/local/include' CXXFLAGS='-O2 -fPIC -arch x86_64 -arch i386'
MACOSX_DEPLOYMENT_TARGET='10.6' CXX='/usr/bin/g++-4.2' F90FLAGS='-O2'
LDFLAGS='-L/opt/local/lib -arch x86_64 -arch i386' OBJC='/usr/bin/gcc-4.2'
FCFLAGS='-O2'
INSTALL='/usr/bin/install -c' OBJCFLAGS='-O2 -arch x86_64 -arch i386'
FFLAGS='-O2'
CC='/usr/bin/gcc-4.2'

PREFIX=/opt/mysql/mysql-5.1.39-build
./configure --prefix=$PREIFX \
--disable-dependency-tracking \
--mandir=$PREFIX/share/man --infodir=$PREFIX/share/info \
--localstatedir=$PREFIX/var/ --libdir=$PREFIX/lib \
--bindir=$PREFIX/bin --includedir=$PREFIX/include \
--datadir=$PREFIX/share/ --sysconfdir=$PREFIX/etc \
--with-extra-charsets=complex \
--with-mysqld-user=mysql \
--without-docs --without-bench --with-partition --with-plugins=all \
--enable-thread-safe-client --with-embedded-server \
--with-pic --with-readline
make clean
make
[6 Oct 2009 16:56] Ryan Schmidt
Hi, Geert. Yes, your script builds without error for me, but it builds 64-bit binaries only, not 32-bit/64-bit universal as desired. This is because none of the variables are getting passed to the Makefile. If you use "export" in front of each variable definition, e.g. "export CFLAGS='-O2 -fPIC -arch x86_64 -arch i386'", you should see the failure.

After a few tests, it seems just requesting to add the embedded server is enough to trigger the problem. Here is the script I used:

#!/bin/bash

export CFLAGS='-O2 -fPIC -arch x86_64 -arch i386'
export CPPFLAGS='-I/opt/local/include'
export CXXFLAGS='-O2 -fPIC -arch x86_64 -arch i386'
export MACOSX_DEPLOYMENT_TARGET='10.6'
export CXX='/usr/bin/g++-4.2'
export F90FLAGS='-O2'
export LDFLAGS='-L/opt/local/lib -arch x86_64 -arch i386'
export OBJC='/usr/bin/gcc-4.2'
export FCFLAGS='-O2'
export INSTALL='/usr/bin/install -c'
export OBJCFLAGS='-O2 -arch x86_64 -arch i386'
export FFLAGS='-O2'
export CC='/usr/bin/gcc-4.2'
./configure \
--disable-dependency-tracking \
--with-embedded-server \
--with-pic
make clean
make
[25 Oct 2009 20:31] Kendall Bennett
Can we get this fixed? I just discovered this when I tried to install MacPorts on my home system, and I NEED a universal install of MySQL for my development environment due to some stupid limitations of Zend Studio. 5.0.86 worked just fine, but now that my system is building 5.1.40, the universal builds get ignored ...
[21 Nov 2009 10:56] Valeriy Kravchuk
Please, check if recent version, 5.1.41, is also affected when you use latest Xcode for 10.6.
[21 Nov 2009 11:01] Ryan Schmidt
Yes, MySQL 5.1.41 is still affected on Mac OS X 10.6.2 with Xcode 3.2.1.

Again, the problem is the libmysqld embedded server. When I updated the mysql5 port in MacPorts to 5.1.41 a few hours ago, I added a "no_embedded_server" variant; MacPorts users who do not need the embedded server but do need a universal build can use this variant:

sudo port install mysql5 +no_embedded_server +universal
[31 Dec 2009 7:20] Geert Vanderkelen
Verified (includes workaround). The problem is that the libmysqld Makefile's are just broken and this makes it difficult to produce universal binaries. (Probably also the reason why MacPorts gives the option to exclude it, smart!)

Talking to engineering, there were some patches and fixes, but they were never approved. There is work on going, but not sure when this will go in.

Workaround: For now, if you don't need libmysqld (most don't) you can use the script below to produce a binary which works 32 and 64bit. If you need libmysqld, build it 2 times: once for i386 and once for x86_64 and distribute as such. IMHO this is a valid workaround. (you might try to use lipo to combine them manually?)

Below script might not need SDK/SDKLIB, but just showing to be complete. Also, I'm using libedit (for the folks that don't have readline compiled on their machines).

#!/bin/bash

SDK="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
SDKLIB="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk"

MACOSX_DEPLOYMENT_TARGET="10.6"

export CFLAGS="-O2 -fPIC -arch i386 -arch x86_64 $SDK"
export CXXFLAGS="-O2 -fPIC -arch i386 -arch x86_64 $SDK"
export LDFLAGS="-arch i386 -arch x86_64 $SDKLIB"

CC="/usr/bin/gcc-4.2"
CXX="/usr/bin/g++-4.2"
OBJC="/usr/bin/gcc-4.2"

INSTALL="/usr/bin/install -c"

PREFIX=/opt/mysql/mysql-5.1.42-universal-ppc
./configure --prefix=$PREFIX \
--disable-dependency-tracking \
--mandir=$PREFIX/share/man --infodir=$PREFIX/share/info \
--localstatedir=$PREFIX/var/ --libdir=$PREFIX/lib \
--bindir=$PREFIX/bin --libexecdir=$PREFIX/bin \
--includedir=$PREFIX/include \
--datadir=$PREFIX/share/ --sysconfdir=$PREFIX/etc \
--with-extra-charsets=complex \
--with-mysqld-user=mysql \
--without-docs \
--with-plugins=all \
--enable-thread-safe-client --without-embedded-server \
--with-pic --with-libedit

if [ $? -eq 0 ]; then
    make clean
    time make -j 2
fi
[16 Jan 2014 13:04] Ståle Deraas
Posted by developer:
 
From OS X 10.8 universal binaries are no longer relevant, as 10.8 only runs on 64bit cpus.