Bug #8059 Include libmysql.a for MinGW32 linking in Windows packages
Submitted: 20 Jan 2005 23:55 Modified: 4 Sep 2007 11:07
Reporter: Jim Winstead Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Packaging Severity:S4 (Feature request)
Version:all OS:Windows (Microsoft Windows)
Assigned to: Kent Boortz CPU Architecture:Any

[20 Jan 2005 23:55] Jim Winstead
Description:
The MinGW32 tools (http://www.mingw.org/) require a "libmysql.a" to be able to link applications against libmysql.dll. We should generate and include these with our Windows binaries.

How to repeat:
This requires some dlltool.exe from MinGW32 and reimp.exe from the MinGW Utilities. (I tested this with MinGW 3.1.0-1 and mingw-utils 0.3.)

shell> cd /path/to/mysql-VER/lib/opt
shell> reimp -d libmysql.lib
shell> dlltool -d LIBMYSQL.def -D libmysql.dll -k -l libmysql.a

I was then able to compile, link, and run one of the tests (which itself requires a patch to include my_global.h before mysql.h).

shell> cd /path/to/mysql-VER/examples/tests
shell> gcc -I../../include -o showdb_test showdb_test.c ../../lib/opt/libmysql.a
[12 May 2005 11:12] Olaf Redmann
I cannot reproduce this.

If a use reimp then i get undefined references.
If a use pexports with the dll i can compile and link my program.
But on execution a get a segmentation fault (it seems something is wrong wit the program stack)

The difference between reimp adn pexports is: 
pexports def:

LIBRARY LIBMYSQL.dll
EXPORTS
_dig_vec_lower DATA
_dig_vec_upper DATA
bmove_upp
client_errors DATA
delete_dynamic
free_defaults
get_defaults_files
getopt_compare_strings
getopt_ull_limit_value
handle_options
init_dynamic_array
insert_dynamic
int2str
is_prefix
list_add
list_delete
load_defaults
my_end
my_getopt_print_errors DATA
my_init
my_malloc
my_memdup
my_no_flags_free
my_path
...

reimp  def:
LIBRARY LIBMYSQL.dll
EXPORTS
_dig_vec_lower
_dig_vec_upper
bmove_upp
client_errors
delete_dynamic
free_defaults
get_defaults_files
getopt_compare_strings
getopt_ull_limit_value
handle_options
init_dynamic_array
insert_dynamic
int2str
is_prefix
list_add
list_delete
load_defaults
my_end
my_getopt_print_errors
my_init
my_malloc
my_memdup
my_no_flags_free
my_path
my_print_help
my_print_variables
my_realloc
my_strdup
myodbc_remove_escape@8
mysql_affected_rows@4
mysql_autocommit@8
mysql_change_user@16
mysql_character_set_name@4

I use the following commd lines:

pexports libmysql.dll >l.def
dlltool -d l.def -D libmysql.dll -k -l libmysql.a

reimp  libmysql.lib
dlltool -d LIBMYSQL.def -D libmysql.dll  -l libmysql.a  -k

and for my program i use:

g++ -c -g -Wall   -I../includes -I../../../../mingw/include -I../../../../mingw/include/mysql -o filesystest.o filesystest.cpp

and:

g++ -g  -o./fTest.exe ./filesystest.o ./libmysql.a -lws2_32 -lwsock32
[15 Jul 2005 9:01] Mirza Hadzic
I tried to link against libmysql.dll directly (which is possible in mingw) and not create .a file at all, but program seg-faults in first mysql_init(NULL) call (seems SP is messed up).
As all workarounds seems not to work I propose increasing severity of this issue. Only possible solution is compiling libmysql.a from scratch using mingw.
[26 Jul 2005 8:28] Mirza Hadzic
Also, please reopen related bug #7706.
[22 Apr 2007 11:00] Michal Čihař
Is there a chance that this issue will be fixed in near future?
[4 Sep 2007 11:07] Kent Boortz
We will not add the MinGW32 "libmysql.a" into the Windows
package. What is included in a binary package should be
supported and well tested, and we don't have the capacity
to do that right now. This might change if community
demand gets very high.

In this case it seems easy enough for the user to create
this "libmysql.a" himself using a couple of freely
available tools.

I will bring up with the documentation team to include
the build instructions in the MySQL reference manual.
[21 Nov 2007 11:38] Bodo Barwich
I'm experiencing the same problem.

I tried several approches to generate the "libmysql.a" file.
I tried reimp, pexports and objdump.
So I generated several "libmysql.a" files.

I was able to compile the project.
I put the "libmysql.dll" in the same folder as the application.
But on the first "mysql_real_connect" the application crashes.
I tried different IDE's, too. It's all the same.

CodeBlocks says: "Segmentation fault in _libmsvrt_a_iname".
[26 Jun 2008 13:21] Bill Hill
Seems to be out by 1 byte - putting a line:
char padding=42;
immediately before the mysql_init(&mysql) and it works.