Bug #109251 Cannot compile 5.7.39 on Ubuntu 22.04 because ssl is not found
Submitted: 30 Nov 2022 16:06 Modified: 18 Jan 2023 23:58
Reporter: Mark Callaghan Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.7.39, 5.7.40 OS:Ubuntu
Assigned to: CPU Architecture:x86

[30 Nov 2022 16:06] Mark Callaghan
Description:
I can compile MySQL 8.0.31 on the same host and that finds cmake. But 5.6.51, 5.7.39 and some 8.0 releases prior to 8.0.31 all fail because they can't find ssl. My blog post on this is here:
http://smalldatum.blogspot.com/2022/11/compiling-mysql-56-57-on-ubuntu-2204.html

I know that 5.6 is end of life, but I think that 5.7 is still active.

How to repeat:

Download source, run cmake:
prefix=~/d/my5739
cmake \
      -DBUILD_CONFIG=mysql_release \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DCMAKE_INSTALL_PREFIX:PATH=$prefix \
      -DWITH_SSL="system" \
      -DWITH_ZLIB="system" \
      -DMYSQL_DATADIR="${prefix}/data" \
      -DMYSQL_UNIX_ADDR="${prefix}/var/mysql.sock" \
      -DENABLED_LOCAL_INFILE=1 \
      -DMYSQL_MAINTAINER_MODE=0 \
      -DWITH_BOOST=$PWD/../boost \
      -DWITH_NUMA=ON \
      ..

The error text from cmake is:
CMake Error at cmake/ssl.cmake:63 (MESSAGE):
  Please install the appropriate openssl developer package.

Call Stack (most recent call first):
  cmake/ssl.cmake:306 (FATAL_SSL_NOT_FOUND_ERROR)
  CMakeLists.txt:603 (MYSQL_CHECK_SSL)

SSL is there, and was found by 8.0.31:
$ find /usr -name \*ssl\*\.a -print
/usr/lib/x86_64-linux-gnu/libssl.a

mdcallag@amd2:~/b/mysql-5.7.39/build$ find /usr -name \*ssl\*\.so -print
/usr/lib/x86_64-linux-gnu/libssl.so
/usr/lib/x86_64-linux-gnu/libssl3.so

$ find /usr -name \*ssl\*\.h -print
/usr/include/ncursesw/cursslk.h
/usr/include/x86_64-linux-gnu/openssl/opensslconf.h
/usr/include/openssl/sslerr_legacy.h
/usr/include/openssl/ssl.h
/usr/include/openssl/ossl_typ.h
/usr/include/openssl/prov_ssl.h
/usr/include/openssl/ssl2.h
/usr/include/openssl/sslerr.h
/usr/include/openssl/ssl3.h
/usr/include/openssl/opensslv.h
/usr/include/cursslk.h

And cmake stdout that references SSL shows that the version numbers were not parsed:
-- OPENSSL_INCLUDE_DIR = /usr/include
-- OPENSSL_LIBRARY = /usr/lib/x86_64-linux-gnu/libssl.so
-- OPENSSL_MAJOR_VERSION =
-- OPENSSL_MINOR_VERSION =
-- OPENSSL_FIX_VERSION =
Cannot find appropriate system libraries for WITH_SSL=system.
Make sure you have specified a supported SSL version.
system (use the OS openssl library),
</path/to/custom/openssl/installation>

Suggested fix:
The root cause is that cmake/ssl.cmake is unable to parse the version number from openssl/openslv.h. My hack to fix this (because I don't know cmake) was to copy/paste the parsing code from the 8.0.31 version of cmake/ssl.cmake.
https://gist.github.com/mdcallag/26ee34e0c5c9358d7b5c7b29a91a1b3e

Perhaps there is another way. Regardless, I hope this error message is made less ambiguous. It would be great for it to indicate which of the 4 problems triggered it (libraries not found, header not found, version number not parsed or wrong).
https://github.com/mysql/mysql-server/blob/c4f63caa8d9f30b2850672291e0ad0928dd89d0e/cmake/...
[1 Dec 2022 10:09] MySQL Verification Team
Hello Mark,

Thank you for the report and feedback.

Thanks,
Umesh
[1 Dec 2022 10:15] MySQL Verification Team
5.7.40 build details

Attachment: 109251_5.7.40.results (application/octet-stream, text), 19.85 KiB.

[7 Jan 2023 7:29] Roel Van de Paar
Thank you Mark for creating this bug.

I am running into this also. While 5.5 and 8.0 compile fine on Ubuntu 22.04, 5.6 and 5.7 fail with this issue.

This bug should be fixed asap IMHO, as it basically renders 5.6 and 5.7 unable to compile on the latest Ubuntu.

The following hack also makes 5.7 compile:

1. Open cmake/ssl.cmake
2. Search for "# If we are invoked with" (around line 239 in current code) and just before that line add the following:

    SET(OPENSSL_INCLUDE_DIR "/usr/include/openssl")
    SET(OPENSSL_LIBRARY "/lib/x86_64-linux-gnu/libssl.a")
    SET(CRYPTO_LIBRARY "/lib/x86_64-linux-gnu/libcrypto.a")
    SET(OPENSSL_VERSION "1.1.1")
    SET(OPENSSL_MAJOR_VERSION "1")
    SET(OPENSSL_MINOR_VERSION "1")
    SET(OPENSSL_FIX_VERSION "1")
    SET(OPENSSL_FOUND TRUE)
    SET(WITH_SSL_PATH TRUE)

3. Compile as normal
[7 Jan 2023 7:42] Roel Van de Paar
The same patch works for 5.6. However, the build will fail with other errors using standard cmake. The issue seems to be a change in C++ standards or similar. Using clang instead of cmake makes the build succeed.
[7 Jan 2023 7:54] Roel Van de Paar
Btw, for 5.6 also search for 'If we are invoked with' and insert the same hack before that line, however that line has a lower line number (around line 205 currently) in 5.6.
[18 Jan 2023 23:58] Mark Callaghan
Replying to a previous comment ...

Whether or not 8.x compiles OK on Ubuntu 22.04 depends on which version of 8.0. AFAIK MySQL 8 became ready for OpenSSL 3 in 8.0.30, so while I can get cmake to work for 8.0.28 with some edits, the build still fails.