Bug #22139 undefined reference to `my_memmem' when compiling tests/mysql_client_test
Submitted: 9 Sep 2006 4:04 Modified: 15 Sep 2006 23:17
Reporter: Carlos Velasco Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.0.24a OS:
Assigned to: Magnus Blåudd CPU Architecture:Any

[9 Sep 2006 4:04] Carlos Velasco
Description:
When building mysql from source distribution:

make[2]: Leaving directory `/compile/mysql-5.0.24a/man'
Making all in tests
make[2]: Entering directory `/compile/mysql-5.0.24a/tests'
if gcc -m64 -DUNDEF_THREADS_HACK -I. -I. -I.. -I../include -I../include     -DDBUG_OFF -O3 -march=nocona   -MT mysql_client_test.o -MD -MP -MF ".deps/mysql_client_test.Tpo" -c -o mysql_client_test.o mysql_client_test.c; \
        then mv -f ".deps/mysql_client_test.Tpo" ".deps/mysql_client_test.Po"; else rm -f ".deps/mysql_client_test.Tpo"; exit 1; fi
/bin/sh ../libtool --preserve-dup-deps --tag=CXX --mode=link g++ -m64  -DDBUG_OFF -O3 -march=nocona -felide-constructors     -fno-exceptions -fno-rtti   -fno-implicit-templates -fno-exceptions -fno-rtti  -rdynamic  -o mysql_client_test  mysql_client_test.o  ../libmysql/libmysqlclient.la  -L../mysys -lmysys -lcrypt -lnsl -lm  -L/usr/lib64 -lssl -lcrypto -lz 
mkdir .libs
g++ -m64 -DDBUG_OFF -O3 -march=nocona -felide-constructors -fno-exceptions -fno-rtti -fno-implicit-templates -fno-exceptions -fno-rtti -rdynamic -o .libs/mysql_client_test mysql_client_test.o  ../libmysql/.libs/libmysqlclient.so -L/usr/lib64 -L/compile/mysql-5.0.24a/mysys -lmysys -lcrypt -lnsl -lm -lssl -lcrypto -lz
mysql_client_test.o: In function `test_bug17667':
mysql_client_test.c:(.text+0xdda): undefined reference to `my_memmem'
collect2: ld returned 1 exit status
make[2]: *** [mysql_client_test] Error 1
make[2]: Leaving directory `/compile/mysql-5.0.24a/tests'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/compile/mysql-5.0.24a'
make: *** [all] Error 2

The problem is that it's trying to link with libmysys.a in /usr/lib64, not with the one in /compile/mysql-5.0.24a/mysys. So if someone has an old built of mysql this will fail.

How to repeat:
I'm using this to build:

CC="gcc -m64" CXX="g++ -m64" \
    CFLAGS="-O3 -march=nocona" \
    CXXFLAGS="-O3 -march=nocona -felide-constructors \
    -fno-exceptions -fno-rtti" \
    ./configure --prefix=/usr --libexecdir=/usr/bin \
    --enable-assembler --localstatedir=/mysql \
    --with-unix-socket-path=/var/mysql.sock \
    --with-berkeley-db --enable-thread-safe-client \
    --enable-local-infile --with-openssl --with-gnu-ld \
    --libdir=/usr/lib64 --with-extra-charsets=all
make pkglibdir=/usr/lib64 pkgincludedir=/usr/include

Suggested fix:
I'm not an automake expert, but this patch works for me.
I have rearranged order moving -lmysys first and added @LIBS@ because my build is thread-safe and it complained about pthread functions not found after reordering.

diff -ur mysql-5.0.24a/tests/Makefile.am mysql-5.0.24a_patched/tests/Makefile.am
--- mysql-5.0.24a/tests/Makefile.am	2006-08-25 23:12:13.000000000 +0200
+++ mysql-5.0.24a_patched/tests/Makefile.am	2006-09-09 04:37:16.000000000 +0200
@@ -40,14 +40,15 @@
 INCLUDES =		-I$(top_builddir)/include -I$(top_srcdir)/include \
 			$(openssl_includes)
 LIBS =			@CLIENT_LIBS@
-LDADD =			@CLIENT_EXTRA_LDFLAGS@ \
+LDADD =			@LIBS@ \
+                        -L../mysys -lmysys \
                         $(top_builddir)/libmysql/libmysqlclient.la
 if HAVE_NETWARE
 mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS)
 mysql_client_test_SOURCES= mysql_client_test.c $(yassl_dummy_link_fix) \
 			../mysys/my_memmem.c
 else
-mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) -L../mysys -lmysys
+mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS)
 mysql_client_test_SOURCES= mysql_client_test.c $(yassl_dummy_link_fix)
 endif
 insert_test_SOURCES=       insert_test.c $(yassl_dummy_link_fix)
[12 Sep 2006 8:25] Magnus Blåudd
We will change so that mysql_client_test is not linked with mysy but rather builds it's own version of ../mysys/my_memem.c
[12 Sep 2006 9:15] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11751

ChangeSet@1.2232, 2006-09-12 11:15:27+02:00, msvensson@shellback.(none) +1 -0
  Bug#22139 undefined reference to `my_memmem' when compiling tests/mysql_client_test
  - Build mysql_client_test from mysql_client_test.c and mysys/my_memmem.c
[12 Sep 2006 9:17] Magnus Blåudd
Carlos, could you please test the patch?
[12 Sep 2006 9:35] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11752

ChangeSet@1.2232, 2006-09-12 11:34:46+02:00, msvensson@shellback.(none) +1 -0
  Bug#22139 undefined reference to `my_memmem' when compiling tests/mysql_client_test
  - Build mysql_client_test from mysql_client_test.c and mysys/my_memmem.c
[12 Sep 2006 12:27] Carlos Velasco
Tested... it works perfectly
[15 Sep 2006 22:21] Chad MILLER
Available in 5.1.12-beta.
[15 Sep 2006 23:17] Paul Dubois
Test suite change. No changelog needed.