Bug #8906 Linker error under MinGW
Submitted: 2 Mar 2005 21:33 Modified: 21 Mar 2005 11:54
Reporter: Nils Durner Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:4.1 OS:Windows (Windows)
Assigned to: Petr Chardin CPU Architecture:Any

[2 Mar 2005 21:33] Nils Durner
Description:
To be able to link against libmySQL.dll, you can generate an import library for GCC using
---
dlltool --input-def include/libmySQL.def --dllname lib/libmySQL.dll --output-lib lib/libmysqlclient.a -A
---

However, if you try to link a test application, the used MySQL function are not found:
---
.libs/mysql.o(.text+0x6a): In function `x': mysql.c:217: undefined reference to `mysql_fetch_lengths@4'
.libs/mysql.o(.text+0x566): In function `x': mysql.c:255: undefined reference to `mysql_init@4'
.libs/mysql.o(.text+0x5c7): mysql.c:268: undefined reference to `mysql_real_connect@32'
.libs/mysql.o(.text+0x5e1):mysql.c:277: undefined reference to `mysql_error@4'
---

This is because the .def shipped with MySQL doesn't contain mangled function names.

The attached patch adds them to the .def file. With it applied, you can link against  an import library created with dlltool.

How to repeat:
1. Get and install MinGW from www.mingw.org
2. Create an import library for libmysql.dll:
---
dlltool --input-def include/libmySQL.def --dllname lib/libmySQL.dll --output-lib lib/libmysqlclient.a -A
---

3. Compile a test application:
---
gcc -I/c/mysql/include -L/c/mysql/lib/ mysql.c -o mysql -lmysqlclient
---

=> linker errors

Suggested fix:
Apply patch.
[2 Mar 2005 21:33] Nils Durner
Patch

Attachment: mysql_def03.diff (text/x-patch), 2.30 KiB.

[3 Mar 2005 18:03] Nils Durner
The dlltool options are wrong, sorry.
It has to be:
---
dlltool --input-def ../include/libmySQL.def --dllname libmySQL.dll --output-lib libmysqlclient.a -k
---
[21 Mar 2005 11:54] Petr Chardin
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

The MinGW's linker error you've referred  are not specific to MySQL. According to MinGW documentation, one needs to perform the following steps to create an import library:
1) Use one of the tools distributed with MinGW  to generate a DEF file from appropriate dll to create an import library later. These tools are reipm and pexports. The latter one might require additional parameters.
2) Create an import library with dlltool from generated DEF file

The DEF file distributed with MySQL Server is not intended to be used for MinGW import library creation. It is provided for information purposes only.  Moreover, it might be removed from future binary releases.

Please refer to
http://www.mingw.org/mingwfaq.shtml#faq-msvcdll
and
http://www.mingw.org/docs.shtml#compilingandbuilding
[18 Dec 2006 17:31] Jose Luis Franzen
Add these lines to patch:

+  mysql_errno@4
+  mysql_insert_id@4

Jose Luis Franzen