Bug #28267 Cannot build with OpenSSL
Submitted: 6 May 2007 15:07 Modified: 9 Jun 2007 17:59
Reporter: Gerry Reno Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S1 (Critical)
Version:5.1.17-beta OS:Any
Assigned to: Magnus Blåudd CPU Architecture:Any

[6 May 2007 15:07] Gerry Reno
Description:
While running the build for 5.1.17-beta I received an error regarding the deprecated use of --use-openssl=/path...  So I changed all references to 'openssl' in the configure to 'ssl' (eg: --use-ssl=/path...).  I restarted the build and then encountered the exact same error listed in bug 25337 ( http://bugs.mysql.com/bug.php?id=25337 ).  Here is the output:

============================================================
make[4]: Entering directory `/root/build/mysql-5.1.17-beta/sql'
if g++ -DMYSQL_SERVER -DDEFAULT_MYSQL_HOME="\"/opt/lampp\"" -DDATADIR="\"/opt/lampp/var/mysql\"" -DSHAREDIR="\"/opt/lampp/share/mysql\"" -DLIBDIR="\"/opt/lampp/lib/mysql\"" -DHAVE_CONFIG_H -I. -I. -I.. -I../include -I../include -I../regex -I. -I   -DTZINFO2SQL -O3    -fno-implicit-templates -fno-exceptions -fno-rtti  -MT mysql_tzinfo_to_sql-tztime.o -MD -MP -MF ".deps/mysql_tzinfo_to_sql-tztime.Tpo" -c -o mysql_tzinfo_to_sql-tztime.o `test -f 'tztime.cc' || echo './'`tztime.cc; \
        then mv -f ".deps/mysql_tzinfo_to_sql-tztime.Tpo" ".deps/mysql_tzinfo_to_sql-tztime.Po"; else rm -f ".deps/mysql_tzinfo_to_sql-tztime.Tpo"; exit 1; fi
/bin/sh ../libtool --preserve-dup-deps --tag=CXX --mode=link g++  -O3    -fno-implicit-templates -fno-exceptions -fno-rtti   -rdynamic  -o mysql_tzinfo_to_sql  mysql_tzinfo_to_sql-tztime.o ../vio/libvio.a ../mysys/libmysys.a ../dbug/libdbug.a ../regex/libregex.a ../strings/libmystrings.a -lz -lpthread -lcrypt -lnsl -lm  -lpthread 
g++ -O3 -fno-implicit-templates -fno-exceptions -fno-rtti -rdynamic -o mysql_tzinfo_to_sql mysql_tzinfo_to_sql-tztime.o  ../vio/libvio.a ../mysys/libmysys.a ../dbug/libdbug.a ../regex/libregex.a ../strings/libmystrings.a -lz -lpthread -lcrypt -lnsl -lm -lpthread
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
mysql_tzinfo_to_sql-tztime.o: In function `Time_zone_utc::gmt_sec_to_TIME(st_mysql_time*, long) const':
tztime.cc:(.text+0x78f): undefined reference to `localtime_to_TIME(st_mysql_time*, tm*)'
mysql_tzinfo_to_sql-tztime.o: In function `Time_zone_system::gmt_sec_to_TIME(st_mysql_time*, long) const':
tztime.cc:(.text+0x7df): undefined reference to `localtime_to_TIME(st_mysql_time*, tm*)'
mysql_tzinfo_to_sql-tztime.o: In function `Time_zone_system::TIME_to_gmt_sec(st_mysql_time const*, char*) const':
tztime.cc:(.text+0x81b): undefined reference to `my_system_gmt_sec'
mysql_tzinfo_to_sql-tztime.o: In function `my_tz_find(THD*, String const*)':
tztime.cc:(.text+0xdf2): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0xef0): undefined reference to `open_system_tables_for_read(THD*, st_table_list*, Open_tables_state*)'
tztime.cc:(.text+0x10ce): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x10f7): undefined reference to `close_system_tables(THD*, Open_tables_state*)'
tztime.cc:(.text+0x126a): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x127d): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x1295): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x1402): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x141f): undefined reference to `sql_print_error(char const*, ...)'
mysql_tzinfo_to_sql-tztime.o:tztime.cc:(.text+0x1430): more undefined references to `sql_print_error(char const*, ...)' follow
mysql_tzinfo_to_sql-tztime.o: In function `my_tz_init(THD*, char const*, char)':
tztime.cc:(.text+0x1ae9): undefined reference to `THD::THD()'
tztime.cc:(.text+0x1b05): undefined reference to `THD::store_globals()'
tztime.cc:(.text+0x1b59): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x1b7e): undefined reference to `THD::store_globals()'
tztime.cc:(.text+0x1e02): undefined reference to `open_system_tables_for_read(THD*, st_table_list*, Open_tables_state*)'
tztime.cc:(.text+0x1e22): undefined reference to `sql_print_warning(char const*, ...)'
tztime.cc:(.text+0x1e6e): undefined reference to `global_system_variables'
tztime.cc:(.text+0x1efd): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x1f13): undefined reference to `THR_THD'
tztime.cc:(.text+0x1f28): undefined reference to `THR_MALLOC'
tztime.cc:(.text+0x1f56): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x1fb2): undefined reference to `close_system_tables(THD*, Open_tables_state*)'
tztime.cc:(.text+0x20cb): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x212c): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x2150): undefined reference to `sql_print_error(char const*, ...)'
tztime.cc:(.text+0x2166): undefined reference to `sql_print_error(char const*, ...)'
collect2: ld returned 1 exit status
make[4]: *** [mysql_tzinfo_to_sql] Error 1
make[4]: Leaving directory `/root/build/mysql-5.1.17-beta/sql'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/build/mysql-5.1.17-beta/sql'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/build/mysql-5.1.17-beta/sql'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/build/mysql-5.1.17-beta'
make: *** [all] Error 2
============================================================

So I applied both patches listed in bug 25337 to sql/Makefile.am.  I cleaned the sql/ directory and then restarted the make but it produced the exact same error again as above.

How to repeat:
Build 5.1.17-beta on my platform: Fedora Core 6 with --use-ssl=/path... configure option.

Suggested fix:
unknown
[6 May 2007 15:24] Gerry Reno
Here is my version of g++:
# g++ --version
g++ (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)

When I google this error about crt1.o: underfined reference to 'main' I get threads that talk about things being compiled with incompatible compiler versions.  Could that be related to the problem here?
[6 May 2007 16:39] Gerry Reno
Here is my configure line:

env LD_RUN_PATH=/opt/lampp/lib LD_LIBRARY_PATH="/opt/lampp/lib" CFLAGS="-O6 -I/opt/lampp/include -L/opt/lampp/lib -Wl,--rpath -Wl,/opt/lampp/lib" ./configure --prefix=/opt/lampp --enable-assembler --enable-local-infile --with-mysqld-user=nobody --with-unix-socket-path=/opt/lampp/var/mysql/mysql.sock --with-extra-charsets=complex --libexecdir=/opt/lampp/sbin --sysconfdir=/opt/lampp/etc --datadir=/opt/lampp/share --localstatedir=/opt/lampp/var/mysql --infodir=/opt/lampp/info --includedir=/opt/lampp/include --mandir=/opt/lampp/man --with-innodb --with-vio --with-ssl=/opt/lampp  --with-ssl-includes=/opt/lampp/include --with-ssl-libs=/opt/lampp/lib --with-archive-storage-engine  --with-federated-storage-engine --with-csv-storage-engine --with-ndbcluster --with-bdb --enable-thread-safe-client || exit 1
[6 May 2007 21:25] Gerry Reno
My original configure had these openssl arguments:
--with-openssl=/opt/lampp  
--with-openssl-includes=/opt/lampp/include 
--with-openssl-libs=/opt/lampp/lib 

Here is the original error:
checking for SSL... configure: error: The flag --with-openssl is deprecated, use --with-ssl

the build exits at this point.

I then changed the openssl configure arguments to:
--with-ssl=/opt/lampp  
--with-ssl-includes=/opt/lampp/include 
--with-ssl-libs=/opt/lampp/lib 

and the build went quite a bit further but still errored out in sql/ as described earlier.

I've also tried a build with these configure arguments:
--with-ssl=/opt/lampp  
--with-openssl-includes=/opt/lampp/include 
--with-openssl-libs=/opt/lampp/lib 

Same results.
[6 May 2007 23:00] Gerry Reno
I just did a build of 5.1 from BitKeeper and had the exact same problems.
[7 May 2007 7:54] Sveta Smirnova
Thank you for the report.

Verified as described.

It seems to be duplicate of bug #25337, but as errors are different, I'll let developers who will fix it to decide if this is a duplicate or not.
[7 May 2007 8:24] Magnus Blåudd
Hi,

in 5.1 there is only one switch to configure to use for ssl. It's called --with-ssl. You can't make up your own. ;)

[msvensson@pilot mysql-5.1]$ ./configure --help | grep ssl
--with-ssl=DIR    Include SSL support

The switch will by default use the SSL library shipped with MySQL sources called yassl.
./configure --with-ssl 

To build with the openSSL library you point out the base dir(where your lib and include are lcoated).
In your example it would be 
./configure --with-ssl=/opt/lampp

But this does not explain the compile failure. Let me check.
[7 May 2007 8:33] Magnus Blåudd
It looks like there is an empty -I in the compile line. That causes the crucial -DTZINFO2SQL to be "sucked into it"...

g++ -DMYSQL_SERVER -DDEFAULT_MYSQL_HOME="\"/opt/lampp\""
-DDATADIR="\"/opt/lampp/var/mysql\"" -DSHAREDIR="\"/opt/lampp/share/mysql\""
-DLIBDIR="\"/opt/lampp/lib/mysql\"" -DHAVE_CONFIG_H -I. -I. -I.. -I../include
-I../include -I../regex -I. -I   -DTZINFO2SQL -O3    -fno-implicit-templates
                             ^^^^^^^^^^^^^^^  
This becomes one directive to the compiler and thus the deinfe is lost cuasing mysql_tz_info_to_sql.c to be compiled in the wrong way.
[7 May 2007 8:53] Magnus Blåudd
My conclusion is that the check for openSSL done by configure in some way outputs the empty -I direcive to the compiler.

The configure check will setup the -I and -L switches and the try to compile a a small program that uses SSL_library_init. If that program can be compiled and linked those -I and -L switches will be used ie. they are saved in $openssl_includes and $openssl_libs to be used in Makefile's

In this case the $openssl_includes variable becomes set to "-I" and that is no good. I believe it's caused by the -I directives you specify in CFLAGS="-O6
-I/opt/lampp/include -L/opt/lampp/lib -Wl,--rpath -Wl,/opt/lampp/lib" which points to the same dir as specified with --with-ssl. Thus it works anyway.

Please try with a minimal configure line and post the results from ./configure when it detects ssl
[7 May 2007 9:07] Magnus Blåudd
Just found a spelling error in config/ac-macros/ssl.m4 causing this error.
[7 May 2007 9:50] 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/26206

ChangeSet@1.2505, 2007-05-07 11:50:38+02:00, msvensson@pilot.blaudden +1 -0
  Bug #28267  	Cannot build with OpenSSL
  - Fix use of uninitialized variable in config/ac-macros/ssl.m4
[7 May 2007 14:03] Gerry Reno
Thanks for the quick attention to this problem.

I applied pending patch 26206 and was able to successfully build 5.1.17-beta as follows:
1st build:
--with-ssl=/opt/lampp  
--with-openssl-includes=/opt/lampp/include 
--with-openssl-libs=/opt/lampp/lib 

2nd build:
--with-ssl=/opt/lampp  
[no specific directives for openssl includes or libs]

The only issue that I still see is one of consistency.  If we are going to use the new --with-ssl directive then we should also be using --with-ssl-includes and --with-ssl-libs rather than the 'openssl' types.  To mix these will be confusing for users.
[7 May 2007 14:40] Gerry Reno
Still some problems.

The build and install completed but when I try to start the server it will not start and I see this in the log:

070507 10:24:55  mysqld started
/opt/lampp/sbin/mysqld: error while loading shared libraries: libssl.so.0.9.8: cannot open shared object file: No such file or directory
070507 10:24:55  mysqld ended

Checking /opt/lampp/lib shows:
ls /opt/lampp/lib/libssl* -l
-rw-r--r-- 1 root root 355534 Apr 13 02:54 /opt/lampp/lib/libssl.a
lrwxrwxrwx 1 root root     15 May  5 23:51 /opt/lampp/lib/libssl.so -> libssl.so.0.9.8
-r-xr-xr-x 1 root root 240516 Apr 17 12:13 /opt/lampp/lib/libssl.so.0.9.8

Checking /opt/lampp/lib/mysql shows:
ls /opt/lampp/lib/mysql/libssl* -l
lrwxrwxrwx 1 root root 18 Apr 12 10:19 /opt/lampp/lib/mysql/libssl.so.0.9.8 -> ../libssl.so.0.9.8

So this library is in place.  And it's been working with the previous mysql installation (5.0.37).

I do notice that now libcrypto has been removed.  It was there previously.
[7 May 2007 15:05] Gerry Reno
libcrypto is there.  I mistyped the name while looking for it.
[7 May 2007 16:37] Gerry Reno
The only way that I can get the server to start is by adding:
export LD_LIBRARY_PATH=/opt/lampp/lib
to my environment.  Is this required?  Shouldn't the server already know where to find the shared libs?
[7 May 2007 17:16] Magnus Blåudd
>The only issue that I still see is one of consistency.  If we are going to use
>the new --with-ssl directive then we should also be using --with-ssl-includes
>and --with-ssl-libs rather than the 'openssl' types.  To mix these will be
>confusing for users.

There are no such options anymore. Did you find refernces in the manual?
[7 May 2007 17:52] Gerry Reno
Sorry about that.  I misunderstood what that meant about the --with-ssl.

The build and install are now working fine.

Should I open another bug about the shared lib error?  Unless I specifically add /opt/lampp/lib to my LD_LIBRARY_PATH env variable the server will not start.
[8 May 2007 8:01] Sveta Smirnova
>Shouldn't the server already know where to find the shared libs?

No, server shouldn't know where to find the shared libs. This is expected behaviour.
[9 May 2007 19:15] Magnus Blåudd
Gerry, it might be the case that the value of LD_RUN_PATH should somehow be compiled into the binary. You can experiment with that.
[9 May 2007 19:42] Gerry Reno
I was thinking that the server should check for LD_LIBRARY_PATH and if found, prepend it to the default compiled-in shared library path.
[22 May 2007 17:01] Bugs System
Pushed into 5.1.19-beta
[9 Jun 2007 17:59] Paul DuBois
No changelog entry needed.