Bug #75502 Error compiling mySQL C-Client Program
Submitted: 14 Jan 2015 10:46 Modified: 16 Feb 2015 18:11
Reporter: Philippe Bellamit Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / C Severity:S1 (Critical)
Version:6.1.5 OS:Windows (Win 7)
Assigned to: CPU Architecture:Any
Tags: Compilation, my_global.h

[14 Jan 2015 10:46] Philippe Bellamit
Description:
Error compiling mySQL C-Client Program

I got this error message at compilation:

 Microsoft Windows [version 6.1.7601]
 Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.

 >dmc ..\mypgm.c
 typedef int int32;
                 ^
 C:\Program Files\MySQL\MySQL Server 5.6\include\my_global.h(863) : Error: 'int32
 ' previously declared as something else
 It was declared as: long
 It is now declared: int
 --- errorlevel 1

Context :
 Windows 7
 Compiler Digital Mars 8.42n 
 MySQL Connector/C 6.1.5  x86
 MySQL Server      5.6.21 x64

Reason :
 In my_config.h, line 363, there is:
 #define SIZEOF_INT 4

 Thus in my_global.h, the one relating to C-Connector in dir below
 C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\include
 we found (lines 636-644):
 #if SIZEOF_INT == 4
 
typedef int int32;
 
typedef unsigned int uint32;

 #elif SIZEOF_LONG == 4

 typedef long int32;

 typedef unsigned long uint32;

 #else

 #error Neither int or long is of 4 bytes width
 
#endif

 This will redefine int32 as int and this is a problem

 In winsock2.h that need to be included before, there is at line 840:
 typedef long int32;

The compiler will detect a new different definition and stop.

Solution : adjust my_global.h to take x64 and winsock2.h context into account

How to repeat:
Have this in top of your C program (Hello World is enough as pre-compil error) :

#include <winsock2.h>
#include <windows.h>

#include <my_attribute.h>
#include <my_global.h>
#include <mysql.h>

Compilation under Windows.

Suggested fix:
Solution : adjust my_global.h to take x64 and winsock2.h context into account
[14 Jan 2015 15:26] Philippe Bellamit
Original my_global.h in Connector-C include directory

Attachment: my_global.h (application/octet-stream, text), 24.91 KiB.

[14 Jan 2015 15:27] Philippe Bellamit
Related to winsock2.h adherence
[20 Jan 2015 6:27] Philippe Bellamit
Do not happen using the v32-x86 version of Client 6.1.5.
Only for the v64 version.
Maybe related to DMC Compiler wich is only 32b ?
Anyway, there is a conflict with windows includes.

Regards
[20 Jan 2015 14:42] Igor Solodovnikov
Hello Philippe,

I think you should use 32-bit version of Connector/C with 32-bit compiler.
And please can you elaborate a bit on the conflict with windows includes? I don't think I fully understand what do you mean saying there is a conflict.
[21 Jan 2015 11:00] Philippe Bellamit
The conflict comes from different definitions of type uint32 :

1) In my_config.h, line 363, there is:
 #define SIZEOF_INT 4

2) Thus in my_global.h, in C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\include, there is lines 636-638):
 #if SIZEOF_INT == 4
 typedef unsigned int int32;
 
Then the compiler stops saying it was already defined as long.

I will switch to the 32b version, and check.
[21 Jan 2015 16:33] Igor Solodovnikov
Hello Philippe,

I did some tests with your example source code. With VS2013 and VS2010 it complies without errors.

The reason for this is that winsock2.h used in Visual Studio 2010 does not define any int32 typedefs. WinSock2.h version from Visual Studio 2013 defines '__int32' but does not use 'int32'. So there is no conflict if you use more or less fresh microsoft compiler and include files on Windows.

Thus the question is what version of winsock2.h is on your include patch and if you can update it.
[16 Feb 2015 18:10] Philippe Bellamit
I have corrected my problem switching from DMC that was crearly obsolete to Visual Studio and standard MS SDK.

It has been a bit of a fight to find the correct libraries to link to in x64 mode, but ended working.

However there is a (minor) bug in my_config.h which redefines differently "inan" after including math.h.

In addition, the static client has incorrect external definitions.
Thus the correct include sequence is:

#include <winsock2.h>
#include <windows.h>
#include <sys\types.h>

// Bug in mysql.h definitions
#ifndef strnicmp

/* from string.h **************/
#define strnicmp _strnicmp
#define stricmp _stricmp
#define strdup _strdup

/* from stdlib.h **************/
#define putenv _putenv

/* from direct.h *************/
#define getcwd _getcwd
#define chdir _chdir

/* from stdio.h **************/
#define fdopen _fdopen
#define fileno _fileno

#endif

// #include <my_config.h> /* Included by my_global.h */
#include <my_global.h>
#include <mysql.h>

... and in addition, it is necessary to add oldnames.lib in link libraries.

Thanks for your assistance.
[16 Feb 2015 18:11] Philippe Bellamit
Solved (but not easily !)