Bug #82202 Cannot link to libmysqlclient.so due to undef my_malloc, my_free and others
Submitted: 12 Jul 2016 16:16 Modified: 31 Jan 2018 8:03
Reporter: Georgi Sotirov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.3.10 OS:Linux (Slackware 14.2)
Assigned to: Bogdan Degtyariov CPU Architecture:Any

[12 Jul 2016 16:16] Georgi Sotirov
Description:
It is not possible to link Connector/ODBC to dynamic libmysqlclient library due to undefined functions including default_charset_info, get_charset_by_csname, my_charset_latin1, my_free and my_malloc (see below excerpt from build log).

[ 49%] Linking CXX executable ../bin/myodbc-installer
cd /usr/src/tmp/mysql-connector-odbc-5.3.6-src/installer && /usr/bin/cmake -E cmake_link_script CMakeFiles/myodbc-installer.dir/link.txt --verbose=1
/usr/bin/g++   -O3 -march=i586 -mtune=i686 -O3 -DNDEBUG   -L/usr/lib  -liodbc -liodbcinst   CMakeFiles/myodbc-installer.dir/myodbc-installer.c.o  -o ../bin/myodbc-installer -rdynamic ../lib/libmyodbc-util.a -L/usr/lib  -liodbc -liodbcinst -lmysqlclient -lpthread -lz -lm -lrt -lssl -lcrypto -ldl -lpthread -lm -liodbcinst -ldl -lrt -lssl -lcrypto -ldl -lpthread
CMakeFiles/myodbc-installer.dir/myodbc-installer.c.o: In function `main':
myodbc-installer.c:(.text.startup+0x214): undefined reference to `get_charset_by_csname'
myodbc-installer.c:(.text.startup+0x233): undefined reference to `default_charset_info'
myodbc-installer.c:(.text.startup+0x272): undefined reference to `default_charset_info'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlwchar_as_utf8_ext':
stringutil.c:(.text+0xe9): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlchar_as_sqlwchar':
stringutil.c:(.text+0x3e8): undefined reference to `my_malloc'
stringutil.c:(.text+0x477): undefined reference to `my_malloc'
stringutil.c:(.text+0x520): undefined reference to `my_free'

I was able to reproduce the problem also with MySQL 5.6, but I haven't noticed before, because before the linking was to the static libmysqlclient.a by default.

How to repeat:
Try to build Connector/ODBC on a Linux system without the static libmysqlclient.a library and with cmake configuration MYSQLCLIENT_STATIC_LINKING=OFF directive.

Suggested fix:
The dynamic library should provide same defines as the static one.
[14 Jul 2016 12:09] Bogdan Degtyariov
Hi Georgi,

Due to the changes in the dynamic version of libmysqlclient 5.7 the Connector/ODBC 5.3.6 cannot be linked against libmysqlclient.so.
This is the expected effect of limiting the symbols exported by libmysqlclient.so strictly to MySQL C API functions.

At this moment the only way of linking for MySQL Connector/ODBC driver is the static linking. Unfortunately, I do not have any information when this is going to change.

Sorry for the inconvenience.
[14 Jul 2016 15:54] Georgi Sotirov
Thanks for clarifying it, but in that case why option MYSQLCLIENT_STATIC_LINKING is OFF by default in 5.3.6? I had to force static linking with -DMYSQLCLIENT_STATIC_LINKING=ON in order to build the package.
[5 Aug 2017 0:15] Anatoli ·
Same here with MySQL Server 5.7.19 and MySQL Connector ODBC 5.3.9. Thanks Georgi for the static linking option.
[29 Aug 2017 10:18] Michal Schorm
Hello, I'd use some clarification.

I'm affected by this issue as well. In Fedora and Red Hat OS family, we strictly use dynamic linking, which makes your ODBC connector unusable, for more than year.

--

You closed this bug as "Not A Bug", with explanation, that the state is expected.
However, after a year there is still no update in documentation, which still encourage developers to build dynmically.

In ODBC connector 5.3.6 release notes you state this bug as solved: https://dev.mysql.com/doc/relnotes/connector-odbc/en/news-5-3-6.html
"Attempt to build Connector/ODBC from source on a Linux platform against the client library and header files shipped with MySQL server 5.7.6 or newer failed. It was due to the changes made to the client library and the header files, to which Connector/ODBC has now been adapted. (Bug #20685833)"

However the fix from bug https://bugs.mysql.com/bug.php?id=76261 did not solve the issue.

--

I see this issue as not resolved yet and the bugs should be re-opened and investigated again in my opinion.
OR the documentation hsould be updated in order to reflect that the dynamic linking ability has been dropped, is not possible to use it now, and there is no plan to fix it.

--

Any update about the situation?
[31 Jan 2018 8:03] Terje Røsten
MySQL Connector/ODBC 5.3.10 supports dynamically linking of MySQL client library:
 https://dev.mysql.com/doc/relnotes/connector-odbc/en/news-5-3-10.html

Rebuild of Fedora mysql-connector-odbc with
  -DMYSQLCLIENT_STATIC_LINKING=OFF

confirms this:

$ rpm --requires -qp mysql-connector-odbc-5.3.10-1.fc28.x86_64.rpm|grep libmysqlclient 
libmysqlclient.so.20()(64bit)
libmysqlclient.so.20(libmysqlclient_20.0)(64bit)