Bug #3256 Compiling MySQL clients on Windows with Borland C++Builder
Description:
Compiling MySQL clients with C++Builder is a little bit different than with VC++, here is the description.
The "2.3.7 Compiling MySQL Clients on Windows" part says: "In your source files, you should include 'my_global.h' before 'mysql.h' ... 'my_global.h' includes any other files needed for Windows compatibility (such as 'windows.h') if you compile your program on Windows". Trying to complie a client with C++Builder, I got the following errors:
1. [C++ Error] config-win.h(106): E2238 Multiple declaration for 'size_t'
typedef unsigned int size_t;
This is because the type is defined in _stddef.h, which defines "multi-includable Definitions for common types, and NULL" as:
typedef unsigned int size_t; //(the same)
Solution:
#if !defined(_SIZE_T) && !defined(_SIZE_T_DEFINED)
typedef unsigned int size_t;
#endif
Or, don't define the type at all
2. [C++ Warning] config-win.h(309): W8017 Redefinition of 'PACKAGE' is not identical
#define PACKAGE "mysql"
This conflicts with the Builder's
#define PACKAGE __declspec(package)
which is of some system level and is defined in Vcl/sysmac.h. The point is the PACKAGE is not used anywhere in MySQL header files, though defined multiple times, so the solution is
//#define PACKAGE "mysql"
3.[C++ Error] mysql_com.h(116): E2303 Type name expected
my_socket fd; /* For Perl DBI/dbd */
This is because winsock.h is not included. For older version of MySQL that didn't require 'my_global.h' (the docs didn't say it!) before 'mysql.h' this was enough:
//#ifdef __LCC__
#include <winsock.h> /* For windows */
//#endif
(__LCC__ is not found anywhere (?!) ). If my_global.h is included before mysql.h then the file should be included in any way (in config-win.h):
#include <windows.h>
#include <winsock.h>
In VCL (C++Builder), the windows.h is always included at a very early compilation stage, so it's unnecessary at all.
4. By the way, compilation succeeds without #include <my_global.h> as well. Moreover, when it gets to compling a more complicated client, my_global.h even causes problems. Indeed, if you look along the lines like
typedef char pchar; /* Mixed prototypes can take char */
typedef float pfloat; /* Mixed prototypes can take float */
and some others, too, you'll see that some common types are used in an unusual way. For ex., in my programs pchar means char *. Moreover,
typedef char bool;
is still worse 'cause it changes the built-in type. With all these type redefinitions, one actually can't include my_global.h in their programs 'cause it changes standard types to something unexpected causing compiling and linking errors. So I didn't inlude it and the client worked (though not tested well)
5. *.lib files (libmySQL.lib) can't be used with Builder - they have to be produced from their dlls (if any) by implib.exe shipped with it or converted with another util also shipped with it - libraries produced by VC++ have a different format that causes linker error.
-----------------------------------------------------------
I'd also give more details on how to compile MySQL on Windows with various options - like without BDB, without the unnecessary charsets etc 'cause one has to dig to it through the source code manually.
How to repeat:
Windows, C++Builder 5
A sample project that is supposed to be a MySQL client
Follow the docs, 2.3.7 Compiling MySQL Clients on Windows
Suggested fix:
See Description
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.