# Custom MariaDB ODBC port



## tommyhp2 (Mar 22, 2020)

Hello all,

I've need of MariaDB ODBC in addition to the client/server installed.  I've looked at the ODBC dependent databases/mariadb-connector-c and it seems to be subset of databases/mariadb10[3,4]-client.  Thus, I tried creating a custom port where the ODBC depends/links to the client instead of the connector C so there wouldn't be a conflict.  The port builds successfully.  However, upon test execution of `isql mysql root`, the library complained: `ld-elf.so.1: /usr/local/lib/libmaodbc.so: Undefined symbol "OPENSSL_init_ssl"`.  I'm at stuck at trying to get the port to link properly.  Below is the relevant portion of the Makefile:


```
LIB_DEPENDS=    libodbc.so:databases/unixODBC \
                libmariadb.so:databases/mariadb104-client

CONFLICTS_INSTALL=      mariadb-connector-* \
                        mariadb10[2,3]-client-odbc \
                        mysql-connector-c* \
                        mysql-connector-odbc*

#USES=          cmake:insource
USES=           cmake:insource ssl compiler:c++11-lib

USE_LDCONFIG=   ${PREFIX}/lib/mariadbconnector-odbc
SITESDIR=       ${PORTNAME}/${PKGNAMESUFFIX:S/^-//}-${PORTVERSION:S/.b$//}
DOCSDIR=        ${PREFIX}/share/doc/mysql

CMAKE_ARGS+=    -DCOMPILATION_COMMENT="FreeBSD Ports" \
                -DWITH_SSL="${OPENSSLBASE}"

#CFLAGS+=       -I${LOCALBASE}/include/mysql
CFLAGS+=        -I${LOCALBASE}/include -I${LOCALBASE}/include/mysql -I${LOCALBASE}/include/openssl

#LDFLAGS+=      -L${LOCALBASE}/lib/mysql
LDFLAGS+=       -L${LOCALBASE}/lib/mysql -L${LOCALBASE}/lib/

PLIST_FILES=    lib/libmaodbc.so

post-install:
        ${RM} -r ${STAGEDIR}${PREFIX}/share/doc/mariadb_connector_odbc

.include <bsd.port.mk>
```
The current port databases/mariadb-connector-c outputs

```
# mariadb-connector-c/work/stage/usr/local/bin/mariadb_config
Copyright 2011-2015 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: mariadb-connector-c/work/stage/usr/local/bin/mariadb_config [OPTIONS]
  --cflags        [-I/usr/local/include/mariadb -I/usr/local/include/mariadb/mysql]
  --include       [-I/usr/local/include/mariadb -I/usr/local/include/mariadb/mysql]
  --libs          [-L/usr/local/lib/mariadb/ -lmariadb -lz -lm -liconv -lssl -lcrypto -liconv]
  --libs_r        [-L/usr/local/lib/mariadb/ -lmariadb -lz -lm -liconv -lssl -lcrypto -liconv]
  --libs_sys      [-lz -lm -liconv -lssl -lcrypto -liconv]
  --version       [10.3.6]
  --cc_version    [3.0.9]
  --socket        [/tmp/mysql.sock]
  --port          [3306]
  --plugindir     [/usr/local/lib/mariadb/plugin]
  --tlsinfo       [OpenSSL 1.1.1e][/CMD]
This is the output of the current version of that connector C:
[CMD] # mariadb-connector-c_tmp/work/stage/usr/local/bin/mariadb_config
Copyright 2011-2019 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: mariadb-connector-c_tmp/work/stage/usr/local/bin/mariadb_config [OPTIONS]
  --cflags        [-I/usr/local/include/mariadb -I/usr/local/include/mariadb/mysql]
  --include       [-I/usr/local/include/mariadb -I/usr/local/include/mariadb/mysql]
  --libs          [-L/usr/local/lib/mariadb/ -lmariadb]
  --libs_r        [-L/usr/local/lib/mariadb/ -lmariadb]
  --libs_sys      [-lz -lm -liconv -lssl -lcrypto -liconv]
  --version       [10.4.3]
  --cc_version    [3.1.7]
  --socket        [/tmp/mysql.sock]
  --port          [3306]
  --plugindir     [/usr/local/lib/mariadb/plugin]
  --tlsinfo       [OpenSSL 1.1.1e]
```
And the output from the client:

```
# /usr/local/bin/mariadb_config
Copyright 2011-2019 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: /usr/local/bin/mariadb_config [OPTIONS]
  --cflags        [-I/usr/local/include/mysql -I/usr/local/include/mysql/mysql -I/usr/local/include]
  --include       [-I/usr/local/include/mysql -I/usr/local/include/mysql/mysql -I/usr/local/include]
  --libs          [-L/usr/local/lib/mysql/ -lmariadb -L/usr/local/lib]
  --libs_r        [-L/usr/local/lib/mysql/ -lmariadb -L/usr/local/lib]
  --libs_sys      [-lz -lm -liconv -lssl -lcrypto -liconv]
  --version       [10.4.12]
  --cc_version    [3.1.7]
  --socket        [/tmp/mysql.sock]
  --port          [3306]
  --plugindir     [/usr/local/lib/mysql/plugin]
  --tlsinfo       [OpenSSL 1.1.1e]
```

As you can see they all link to the OpenSSL from port.  Would someone please help me getting past this undefined symbol error?

Thanks,
Tommy

[EDIT]
Here's the output of configure:


```
===>  Applying FreeBSD patches for mariadb104-client-odbc-3.1.6
===>   mariadb104-client-odbc-3.1.6 depends on file: /usr/local/bin/cmake - found
===>   mariadb104-client-odbc-3.1.6 depends on executable: ninja - found
===>   mariadb104-client-odbc-3.1.6 depends on file: /usr/local/lib/libcrypto.so.11 - found
===>   mariadb104-client-odbc-3.1.6 depends on shared library: libodbc.so - found (/usr/local/lib/libodbc.so)
===>   mariadb104-client-odbc-3.1.6 depends on shared library: libmariadb.so - found (/usr/local/lib/mysql/libmariadb.so)
===>  Configuring for mariadb104-client-odbc-3.1.6
===>  Performing in-source build
/bin/mkdir -p /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src
-- The C compiler identification is Clang 8.0.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Libraries installation dir: lib
-- Autentication Plugins installation dir: lib/mysql/plugin
-- Configuring to build without SSL support
-- There is no Connector/C sub-project folder, linking against libmariadb installed on the system
-- Looking for floor
-- Looking for floor - not found
-- Looking for floor in m
-- Looking for floor in m - found
-- Found odbc_config: /usr/local/bin/odbc_config
-- Found ODBC Driver Manager libraries: /usr/local/lib
-- Checking if SQLColAttribute expects SQLPOINTER FALSE
-- Linking Connector/C library statically(mariadbclient)
-- Version script: /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src/maodbc.def
-- Documetnation installed to ./share/doc/mariadb-connector-odbc/
-- License file installed to ./share/doc/mariadb-connector-odbc/
-- freebsd
-- License File: /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src/COPYING
-- ReadMe File: /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src/README
-- Source Package Filename: mariadb-connector-odbc-3.1.6-ga-src.TGZ
-- Configuring done
-- Generating done
```

As you can see, it did find the libcrypto from OpenSSL port.


----------



## tommyhp2 (Mar 22, 2020)

Even when I explicitly define the SSL:

```
CMAKE_ARGS+=    -DCOMPILATION_COMMENT="FreeBSD Ports" \
                -DWITH_SSL="OPENSSL"
```
and the corresponding configure output:

```
===>  Applying FreeBSD patches for mariadb104-client-odbc-3.1.6
===>   mariadb104-client-odbc-3.1.6 depends on file: /usr/local/bin/cmake - found
===>   mariadb104-client-odbc-3.1.6 depends on executable: ninja - found
===>   mariadb104-client-odbc-3.1.6 depends on file: /usr/local/lib/libcrypto.so.11 - found
===>   mariadb104-client-odbc-3.1.6 depends on shared library: libodbc.so - found (/usr/local/lib/libodbc.so)
===>   mariadb104-client-odbc-3.1.6 depends on shared library: libmariadb.so - found (/usr/local/lib/mysql/libmariadb.so)
===>  Configuring for mariadb104-client-odbc-3.1.6
===>  Performing in-source build
/bin/mkdir -p /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src
-- The C compiler identification is Clang 8.0.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Libraries installation dir: lib
-- Autentication Plugins installation dir: lib/mysql/plugin
-- Found OpenSSL: /usr/local/lib/libcrypto.so (found version "1.1.1e")
-- Configuring to build with OpenSSL /usr/local/lib/libssl.so;/usr/local/lib/libcrypto.so
-- There is no Connector/C sub-project folder, linking against libmariadb installed on the system
-- Looking for floor
-- Looking for floor - not found
-- Looking for floor in m
-- Looking for floor in m - found
-- Found odbc_config: /usr/local/bin/odbc_config
-- Found ODBC Driver Manager libraries: /usr/local/lib
-- Checking if SQLColAttribute expects SQLPOINTER FALSE
-- Linking Connector/C library statically(mariadbclient)
-- Version script: /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src/maodbc.def
-- Documetnation installed to ./share/doc/mariadb-connector-odbc/
-- License file installed to ./share/doc/mariadb-connector-odbc/
-- freebsd
-- License File: /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src/COPYING
-- ReadMe File: /wrkdirs/usr/ports/databases/mariadb104-client-odbc/work/mariadb-connector-odbc-3.1.6-ga-src/README
-- Source Package Filename: mariadb-connector-odbc-3.1.6-ga-src.TGZ
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_COLOR_MAKEFILE
    CMAKE_CXX_COMPILER
    CMAKE_CXX_FLAGS
    CMAKE_CXX_FLAGS_DEBUG
    CMAKE_CXX_FLAGS_RELEASE
    CMAKE_C_FLAGS_DEBUG
    CMAKE_EXE_LINKER_FLAGS
    CMAKE_MODULE_LINKER_FLAGS
    CMAKE_VERBOSE_MAKEFILE
    COMPILATION_COMMENT
    THREADS_HAVE_PTHREAD_ARG
```

Testing with `isql` still errors on undefined symbol.


----------



## tommyhp2 (Mar 22, 2020)

I did some debugging via 'readelf':


```
# readelf -a /usr/local/lib/libmaodbc.so | grep 'SSL_init'
00000008cfb8 006c00000007 R_X86_64_JUMP_SLOT  0000000000000000 OPENSSL_init_ssl + 0
   108: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND OPENSSL_init_ssl

# readelf -a /usr/local/lib/mysql/libmariadb.so | grep 'SSL_init'
000000054408 005700000007 R_X86_64_JUMP_SLOT  0000000000000000 OPENSSL_init_ssl + 0
    87: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND OPENSSL_init_ssl@OPENSSL_1_1_0 (7)

# readelf -a /usr/local/lib/mysql/libmariadbclient.a | grep 'SSL_init'
00000000003e 001a00000004 R_X86_64_PLT32      0000000000000000 OPENSSL_init_ssl + fffffffffffffffc
    26: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND OPENSSL_init_ssl
```

From the above, does anyone think the root cause is upstream client (libmariadbclient) that's linked to?


----------



## BS:D (Jul 4, 2021)

I have the same issue with this, I decided to compile the maria-connector-odbc port with LibreSSL instead of OpenSSL just to see what would happen, now when I run isql this is the output:


```
ld-elf.so.1: /usr/local/lib/mariadb/libmaodbc.so: Undefined symbol "CRYPTO_THREADID_get_callback"
```

Tested inside a jail on FreeBSD 12.2-RELEASE-p9


----------

