logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Building & Member Downloads View previous topic :: View next topic
Reply to topic   Topic: Compiling apr-util with mysql support
Author
kimboslice



Joined: 30 Nov 2022
Posts: 4
Location: Canada

PostPosted: Fri 12 Jan '24 19:01    Post subject: Compiling apr-util with mysql support Reply with quote

With the help from this thread I am able to compile apache without issue, however when trying to use mod_dbd with mysql I get an error complaining apr_dbd_mysql.so cannot be found... This issue occurs with builds from here as well as ApacheHaus

How can I compile this?
Back to top
kimboslice



Joined: 30 Nov 2022
Posts: 4
Location: Canada

PostPosted: Fri 12 Jan '24 20:20    Post subject: Reply with quote

Found this in the makefile for apr-util

Code:
# Provide a DBD_LIST argument after configuring LIB and INCLUDE with
# the SDK paths of the corresponding client support libraries.
# ODBC is always built on Windows, so it does not get included in DBD_LIST
# Note that at this time, none of these are supported on win32, per say.



Why are none supported on windows except odbc? it is not possible? Question

Edit: and then theres this in the readme

Code:
On windows, selection of supported drivers is via the environment values
DBD_LIST (for mysql, oracle, pgsql, sqlite2 and/or sqlite3)
and DBM_LIST (db and/or gdbm).  DBD odbc and DBM sdbm are unconditionally
compiled and installed, do not include these in the list.


Seems contradictory?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7318
Location: Germany, Next to Hamburg

PostPosted: Tue 16 Jan '24 13:29    Post subject: Reply with quote

That is defined in https://github.com/apache/httpd/blob/trunk/Makefile.win#L33

in the old days I used to change

https://github.com/apache/httpd/blob/trunk/Makefile.win#L358

from
Code:

for %d in (odbc $(DBD_LIST)) do \


to

Code:

for %d in (odbc mysql $(DBD_LIST)) do \


Also https://github.com/apache/httpd/blob/trunk/Makefile.win#L365 and https://github.com/apache/httpd/blob/trunk/Makefile.win#L370 the same way.
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 325
Location: UK

PostPosted: Tue 16 Jan '24 22:42    Post subject: Reply with quote

As you've found out, the CMakeLists.txt file shipped with APRUTIL doesn't contain logic to build DBD files for MySQL; just ODBC.

Based on the CMake build thread you've referenced, as an experiment, I've tried hacking the apr-util-1.6.3 CMakeLists.txt file to support MySQL, with some success, but can't vouch if the resulting DBD files will work.

Firstly, you'll need to install MySQL server to get copies of the relevant include files, mysql.h, etc., and also library files libmysql.lib, etc. At the time of writing the MySQL download for me was V8.0.35, and installs to "C:\Program Files\MySQL\MySQL Server 8.0". This is a pain, since the path contains space characters, so for your build process you might want to copy the include and lib directories somewhere else, without embedded spaces in the path. Indeed, you may not need all the server files for your Apache target.

Next, you'll need to make two minor changes to the dbd\apr_dbd_mysql.c file. One to provide a definition of my_bool, and another to avoid calling my_init(), which was deprecated externally as of V8.0.2. The current code calls this function, and so fails to link.

The following diff file shows the changes I made.

Code:

C:\Development\Apache24\src\apr-util-1.6.3\dbd>diff -u apr_dbd_mysql.c.FCS apr_dbd_mysql.c
--- apr_dbd_mysql.c.FCS Fri Jan 27 13:32:52 2023
+++ apr_dbd_mysql.c     Tue Jan 16 19:47:46 2024
@@ -50,6 +50,14 @@

 #include "apr_dbd_internal.h"

+/* MySQL 8.0 replaces my_bool with C99 bool. Earlier versions of MySQL had
+* a typedef to char. Gem users reported failures on big endian systems when
+* using C99 bool types with older MySQLs due to mismatched behavior. */
+#ifndef HAVE_TYPE_MY_BOOL
+#include <stdbool.h>
+typedef bool my_bool;
+#endif
+
 /* default maximum field size 1 MB */
 #define FIELDSIZE 1048575

@@ -1262,7 +1270,7 @@

 static void dbd_mysql_init(apr_pool_t *pool)
 {
-#if MYSQL_VERSION_ID < 100000
+#if MYSQL_VERSION_ID < 80020
     my_init();
 #endif
     mysql_thread_init();

Next, there are some revisions to the CMakeLists.txt file to support DBD MySQL (basically clone the ODBC code), along with hard coding paths to the MySQL include and library files. Given more time, I'd remove these and pass them as parameters to CMake, but for now I've hardcoded the MySQL path with the embedded spaces.

Code:

C:\Development\Apache24\src\apr-util-1.6.3>diff -u CMakeLists.txt.FCS CMakeLists.txt
--- CMakeLists.txt.FCS  Wed Jan 18 10:22:39 2023
+++ CMakeLists.txt      Tue Jan 16 20:20:55 2024
@@ -25,6 +25,7 @@

 OPTION(APU_HAVE_CRYPTO      "Crypto support"                            OFF)
 OPTION(APU_HAVE_ODBC        "Build ODBC DBD driver"                     ON)
+OPTION(APU_HAVE_MYSQL       "Build MySQL DBD driver"                    ON)
 OPTION(APR_HAS_LDAP         "LDAP support"                              ON)
 OPTION(INSTALL_PDB          "Install .pdb files (if generated)"         ON)
 OPTION(APR_BUILD_TESTAPR    "Build the test suite"                      OFF)
@@ -32,6 +33,8 @@
 SET(APR_INCLUDE_DIR         "${CMAKE_INSTALL_PREFIX}/include"           CACHE STRING "Directory with APR include files")
 SET(APR_LIBRARIES           "${CMAKE_INSTALL_PREFIX}/lib/libapr-1.lib"  CACHE STRING "APR library to link with")

+SET(MYSQL_LIBRARIES            "C:/Program Files/MySQL/MySQL Server 8.0/lib/libmysql.lib" CACHE STRING "MySQL libraries to link with")
+
 IF(NOT EXISTS "${APR_INCLUDE_DIR}/apr.h")
   MESSAGE(FATAL_ERROR "APR include directory ${APR_INCLUDE_DIR} is not correct.")
 ENDIF()
@@ -95,11 +98,14 @@
 #         manually delete apu.h in PROJECT_SOURCE_DIR/include if
 #         you've generated apu.h before using a different build

+SET(MYSQL_INCLUDE_DIR         "C:/Program Files/MySQL/MySQL Server 8.0/include"           CACHE STRING "Directory with MySQL include files")
+
 SET(APR_INCLUDE_DIRECTORIES
   ${PROJECT_BINARY_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}/include
   ${CMAKE_CURRENT_SOURCE_DIR}/include/private
   ${APR_INCLUDE_DIR}
+  ${MYSQL_INCLUDE_DIR}
 )

 INCLUDE_DIRECTORIES(${APR_INCLUDE_DIRECTORIES} ${XMLLIB_INCLUDE_DIR})
@@ -264,6 +270,17 @@
   SET_TARGET_PROPERTIES(apr_dbd_odbc-1 PROPERTIES COMPILE_FLAGS "-DAPR_DECLARE_IMPORT -DAPU_DECLARE_IMPORT -DDLL_NAME=apr_dbd_odbc")
 ENDIF()

+IF(APU_HAVE_MYSQL)
+  ADD_LIBRARY(apr_dbd_mysql-1 SHARED dbd/apr_dbd_mysql.c libaprutil.rc)
+  SET(install_targets ${install_targets} apr_dbd_mysql-1)
+  SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/apr_dbd_mysql-1.pdb)
+  SET(dbd_drivers ${dbd_drivers} mysql)
+  TARGET_LINK_LIBRARIES(apr_dbd_mysql-1 libaprutil-1 ${APR_LIBRARIES} ${MYSQL_LIBRARIES})
+  SET_PROPERTY(TARGET apr_dbd_mysql-1 APPEND PROPERTY LINK_FLAGS /export:apr_dbd_mysql_driver)
+  SET_TARGET_PROPERTIES(apr_dbd_mysql-1 PROPERTIES COMPILE_DEFINITIONS "APU_HAVE_MYSQL;HAVE_SQL_H;APU_DECLARE_IMPORT;APR_DECLARE_IMPORT;APU_DSO_MODULE_BUILD;WINNT")
+  SET_TARGET_PROPERTIES(apr_dbd_mysql-1 PROPERTIES COMPILE_FLAGS "-DAPR_DECLARE_IMPORT -DAPU_DECLARE_IMPORT -DDLL_NAME=apr_dbd_mysql")
+ENDIF()
+
 IF(APR_HAS_LDAP)
   ADD_LIBRARY(apr_ldap-1 SHARED ldap/apr_ldap_init.c ldap/apr_ldap_option.c
               ldap/apr_ldap_rebind.c libaprutil.rc)
@@ -345,6 +362,7 @@
 MESSAGE(STATUS "  APR include directory ........... : ${APR_INCLUDE_DIR}")
 MESSAGE(STATUS "  APR libraries ................... : ${APR_LIBRARIES}")
 MESSAGE(STATUS "  DBD ODBC driver ................. : ${APU_HAVE_ODBC}")
+MESSAGE(STATUS "  DBD MYSQL driver ................ : ${APU_HAVE_MYSQL}")
 MESSAGE(STATUS "  APU_HAVE_CRYPTO ................. : ${APU_HAVE_CRYPTO}")
 MESSAGE(STATUS "  APR_HAS_LDAP .................... : ${APR_HAS_LDAP}")
 MESSAGE(STATUS "  Build test suite ................ : ${APR_BUILD_TESTAPR}")

Using the CMake HowTo script, for APRUTIL this builds apr_dbd_mysql.dll and import library apr_dbd_mysql-1.lib. You can change the CMakeLists.txt code to build a static library should you prefer.

Hope this helps.
Back to top
nono303



Joined: 20 Dec 2016
Posts: 197
Location: Lille, FR, EU

PostPosted: Thu 18 Jan '24 17:05    Post subject: Reply with quote

Thx @tangent!
Fyi, patched apr_dbd_mysql.c works fine for nmake build
Code:
nmake %NMAKE_OPTS% /f Makefile.win ^
USEMAK=1 ^
ARCH="%archmsbuild% Release" ^
APU_PATH=%PATH_SRC%\apr-util ^
API_PATH=%PATH_SRC%\apr-iconv ^
APR_PATH=%PATH_SRC%\apr ^
DBD_LIST="sqlite3 mysql" ^
XML_PARSER="libexpat" ^
CRYPTO_LIST="openssl" ^
PREFIX=%PATH_INSTALL% ^
SystemRoot=%SystemRoot% ^
buildall install
Back to top


Reply to topic   Topic: Compiling apr-util with mysql support View previous topic :: View next topic
Post new topic   Forum Index -> Building & Member Downloads