Search the MySQL manual:
MySQL Manual

Buy this Reference Manual in softcover from Barnes & Noble!

/ / Up / Table of Contents

2.6.2.6 Компиляция MySQL-клиентов в среде Windows

В файлах исходных текстов следует перед `mysql.h' включить `windows.h':

#if defined(_WIN32) || defined(_WIN64)
#include 
#endif
#include 

Линковать свою программу можно либо с использованием динамической библиотеки `libmysql.lib', которая является просто оболочкой для загрузки `libmysql.dll' по требованию, либо со статической библиотекой `mysqlclient.lib'.

Отметим, что поскольку библиотеки mysqlclient компилируются как потоковые библиотеки, следует скомпилировать вашу программу так, чтобы была разрешена многопочность!

User Comments

Posted by on Tuesday January 29 2002, @8:30am [Delete] [Edit]

I am trying to link with the mysqlclient.lib and
keep getting errors like these

mysqlclient.lib(libmysql.obj) : error LNK2001:
unresolved external symbol _WSAGetLastError@0

I'm running on win2k with vc6.

Posted by on Friday February 8 2002, @7:54am [Delete] [Edit]

Yup, I have the same problem using the mingw compiler (gcc) under Win2k.

Posted by Thomas Koch on Sunday February 10 2002, @8:02am [Delete] [Edit]

I've the same Problem too. (LNK Error with
unresolved symbols in a VC++ 6.0 on Windows 98).
I had alredy try it to compile it multithreated
and to include the wondows.h in my application
but the problem remains. Can anyone give me a
good hint to solve this problem. (Is it necessary
to have a mysqlclient.lib compiled with the
VC++ ? or where one can get the source for the
library)

Posted by Dan Dickinson on Thursday February 21 2002, @8:46am [Delete] [Edit]

I solved some of those link problems (using gcc
on Win2K) with these options:
-lm -lwsock32 -luser32 -lgcc
However, I still get an unresolved _chkstk symbol
in mysqlclient.lib.

Posted by [name withheld] on Monday March 11 2002, @6:14pm [Delete] [Edit]

It took me a couple of hours to iron the problems
out, but I succeeded in compiling a client under
Microsoft Visual C++ version 6.0. mysql_com.h
causes problems with sockets unless winsock.h is
included beforehand. Also, VC++ included a library
that caused conflicts with mysqlclient.lib, which
I took care of with a directive to the linker to
ignore that library (I'm not at the lab anymore,
so I can't look up the exact name of that library;
if you run into the same problem I did, just add
the directive that the linker suggests when it fails).

Posted by on Monday December 9 2002, @12:16am [Delete] [Edit]

the linker problem I have solved.
see
www.dvrsol.com/programming.html#mymingw
here you can download client library for mingw
compiler

Posted by Monaco Olivier on Thursday February 27 2003, @2:41am [Delete] [Edit]

Previous comment permit to compile a MySQL client using libmysql.dll file under GCC for Windows (Dev-C++). But if you want to use mysqlclient.lib you need more manipulation.

Tools to use :
- dlltool.exe which comes with GCC
- pexports.exe from http://starship.python.net/crew/kernr/mingw32/Notes.html for example

1) First you need to create de def file from your ntdll.dll :

pexports c:\winnt\system32\ntdll.dll > c:\mylibs\ntdll.def

This command line extract each exports from ntdll.dll and put its in ntdll.def. If you prefer more complex command line do

echo EXPORT > c:\mylibs\ntdll.def
nm c:\winnt\system32\ntdll.dll | grep " T _" | sed "s/.* T _//" >> c:\mylibs\ntdll.def

It's same.

2) You need to create a .a file for gcc from ntdll.dll and ntdll.def

dlltool --input-def c:\mylibs\ntdll.def --dllname ntdll.dll --output-lib c:\mylibs\libmyntdll.a

Don't name the .a file as libntdll.a because standard libs of GCC include libntdll.a. But this version seem to don't content chkstk function symbol...

3) Now configure your GCC (I'm using Dev-C++) :

Library directory to include :
c:\mylibs

Liker directives :
c:\mysql\lib\mysqlclient.lib -lws2_32 -lmsvcrt20 -lmyntdll

These directives permit you to incule mysqlclient.lib in link process which need libws2_32.a form Windows Socket API, libmsvcrt20.a because mysqlclient.lib was compiled with MS Visual C++ and libmyntdll.a for _chkstk function...

For moment I don't have tested all function of mysqlclient.lib to be sure of no errors but I'm think it's good :))

Good luck...

Note : your program need ntdll.dll (which is part of Windows NT/2000/XP), msvcrt20.dll and ws2_32.dll (which comes with Windows 2000/XP).

Olivier

Add your own comment.

Top / / / Up / Table of Contents