Bug #3256 Compiling MySQL clients on Windows with Borland C++Builder
Submitted: 22 Mar 2004 5:30 Modified: 1 Mar 2013 12:56
Reporter: Sergei Kulakov (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S4 (Feature request)
Version:4.0.18 Source OS:Windows (Windows)
Assigned to: CPU Architecture:Any

[22 Mar 2004 5:30] Sergei Kulakov
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
[23 Mar 2004 9:13] MySQL Verification Team
Yes our source isn't prepared for Borland compilers, I am changing
for feature request. The work around is like you said create the
libmysql.lib from libmysql.dll using the implib tool, is like how
WinMySQLAdmin was compiled.

Thank you for the report.
[7 Sep 2004 13:23] Ash Berlin
For v4.1 i had to use the -a option to implib, else the compiler was complaining about unresolved external _my_init
[1 Mar 2013 12:56] Yngve Svendsen
MySQL 4.x is long past EOL, and C++Builder is no longer as widespread as it was historically. Thus closing this request.