Bug #110355 compiling source code error when cmake with -DWITH_JEMALLOC=true
Submitted: 14 Mar 2023 7:40 Modified: 14 Mar 2023 9:20
Reporter: bin wang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:Ver 8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[14 Mar 2023 7:40] bin wang
Description:

when compiling jemalloc  into MySQL  , document  has this option 

-DWITH_JEMALLOC=bool  
Whether to link with -ljemalloc. If enabled, built-in malloc(), calloc(), realloc(), and free() routines are disabled. The default is OFF.

set -DWITH_JEMALLOC=true can build jemalloc   into MySQL  .

How to repeat:
 cmake .        -DSYSCONFDIR=/user/conf/mysql   -DCMAKE_INSTALL_PREFIX=/user/mysql   -DMYSQL_DATADIR=/user/data/mysql   -DMYSQL_UNIX_ADDR=/user/run/mysql/mysql.sock   -DMYSQL_TCP_PORT=3306   -DDEFAULT_CHARSET=utf8mb4   -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci   -DENABLED_LOCAL_INFILE=1   -DCOMPILATION_COMMENT="8.0-MySQL"   -DWITH_SSL=system   -DWITH_ZLIB=system   -DWITH_DEBUG=ON   -DWITH_PARTITION_STORAGE_ENGINE=ON   -DWITH_INNOBASE_STORAGE_ENGINE=ON   -DWITH_ARCHIVE_STORAGE_ENGINE=ON   -DWITH_BLACKHOLE_STORAGE_ENGINE=ON   -DWITH_PERFSCHEMA_STORAGE_ENGINE=ON   -DWITH_BOOST=/root/mysql-8.0.32/boost   -DFORCE_INSOURCE_BUILD=1  -DWITH_JEMALLOC=true  -DWITH_LIBEVENT=bundled 

set -DWITH_JEMALLOC=true 

then I have this error at last.

-- LIBEVENT_VERSION (bundled) /
-- LIBEVENT_INCLUDE_DIRS /root/mysql-8.0.32/extra/libevent/libevent-2.1.11-stable/include;/root/mysql-8.0.32/extra/libevent/libevent-2.1.11-stable/include
-- LIBEVENT_LIBRARIES event_core;event_extra;event_openssl;event_pthreads
CMake Error at cmake/libevent.cmake:166 (MESSAGE):
  LIBEVENT version must be at least 2.1, found /.

  Please use -DWITH_LIBEVENT=bundled
Call Stack (most recent call first):
  CMakeLists.txt:1880 (MYSQL_CHECK_LIBEVENT)

but my environmet LIBEVENT  has already 2.1.11, meet cmake  environmental requirements  .cost much time to find out the problem is lack of  libjemalloc ,is noting to do with LIBEVENT version which may mislead  others.

Suggested fix:

So print the accurate message  is needed , which can save time  and convenient

-- RUN_OUTPUT MESSAGE  is /root/mysql-8.0.32/CMakeFiles/CMakeTmp/cmTC_fd77b: error while loading shared libraries: libjemalloc.so.2: cannot open shared object file: No such file or directory

CMake Warning at cmake/libevent.cmake:82 (MESSAGE):
  malloc lib file not found need export LD_PRELOAD=libpath/libjemalloc.so.2
Call Stack (most recent call first):
  cmake/libevent.cmake:164 (FIND_LIBEVENT_VERSION)
  CMakeLists.txt:1880 (MYSQL_CHECK_LIBEVENT)

+++ mysql-8.0.31/cmake/libevent.cmake   2023-03-14 23:39:19.898170151 +0800
@@ -52,7 +52,6 @@
   UNSET(LIBEVENT_PTHREADS)
   UNSET(LIBEVENT_PTHREADS CACHE)
 ENDMACRO()
-
 MACRO(FIND_LIBEVENT_VERSION)
   SET(TEST_SRC
     "#include <event.h>
@@ -78,7 +77,10 @@
   # MESSAGE(STATUS "TRY_EVENT COMPILE_TEST_RESULT is ${COMPILE_TEST_RESULT}")
   # MESSAGE(STATUS "TRY_EVENT COMPILE_OUTPUT_VARIABLE is ${OUTPUT}")
   # MESSAGE(STATUS "TRY_EVENT RUN_OUTPUT_VARIABLE is ${RUN_OUTPUT}")
-
+  MESSAGE(STATUS "RUN_OUTPUT MESSAGE  is ${RUN_OUTPUT}")  
+  IF(RUN_OUTPUT MATCHES   "error while loading shared libraries: libjemalloc.so.2")
+    MESSAGE(WARNING  "malloc lib file not found  need export LD_PRELOAD=libpath/libjemalloc.so.2")
+  ENDIF()
[14 Mar 2023 7:48] bin wang
suggested add  patch

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: jemalloc.patch (application/octet-stream, text), 915 bytes.

[14 Mar 2023 9:20] MySQL Verification Team
Hello bin wang,

Thank you for the report and contribution.

regards,
Umesh