Bug #438 mysql.h has several errors regarding if user is compiling on windows
Submitted: 16 May 2003 8:54 Modified: 26 May 2003 5:02
Reporter: Adam Clauss Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.12 OS:Windows (Windows (any))
Assigned to: CPU Architecture:Any

[16 May 2003 8:54] Adam Clauss
Description:
Regarding the C++ include files that are sent with mysql-4.0.12-win32.zip:
There is a bug in the main include file (mysql.h).  Towards the top, there is a block of code reading:

<snip>
#ifdef __LCC__
#include <winsock.h>				/* For windows */
#endif
typedef char my_bool;
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
#define __WIN__
#endif
</snip>

First of all, I am running VC++.NET, and it has no idea what __LCC__
is, it doesn't ever define it.  I have to include <winsock.h> manually if I want it to work right.  What it DOES define is __WIN__.  Which seems to be handled in the next block of #if defines...

How to repeat:

Suggested fix:
So, I suggest the following change:

<snip>
typedef char my_bool;
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
#define __WIN__
#endif
#ifdef __WIN__
#include <winsock.h>				/* For windows */
#endif
</snip>
[16 May 2003 10:43] MySQL Verification Team
I tested the Windows 4.0.12 source release against the Visual Studio 2002
Version 7.0.9466 without to find any problem regarding mysql.h, besides the
usual convert for VC++ 7.0 and the compiler left out the dependencies, since
the project files are for version VC++ 6.0, I can't assume that as a bug.

Regarding: #ifdef __LCC__ I left open the reason why was added because
probably only Monty knows the real reason.
[16 May 2003 12:19] Adam Clauss
Well, the problem I had was related to the fact that the __LCC__ being undefined.  With that being undefined, it never included winsock.h.  This caused SOCKET to never be defined.  So in the struct that my_socket is used in (mysql_com.h):
typedef struct st_net {
  Vio* vio;
  unsigned char *buff,*buff_end,*write_pos,*read_pos;
  //my_socket fd;					/* For Perl DBI/dbd */
  my_socket fd;					/* For Perl DBI/dbd */
  unsigned long max_packet,max_packet_size;
  unsigned int last_errno,pkt_nr,compress_pkt_nr;
  unsigned int write_timeout, read_timeout, retry_count;
  int fcntl;
  char last_error[MYSQL_ERRMSG_SIZE];
  unsigned char error;
  my_bool return_errno,compress;
  /*
    The following variable is set if we are doing several queries in one
    command ( as in LOAD TABLE ... FROM MASTER ),
    and do not want to confuse the client with OK at the wrong time
  */
  unsigned long remain_in_buf,length, buf_length, where_b;
  unsigned int *return_status;
  unsigned char reading_or_writing;
  char save_char;
  my_bool no_send_ok;
  gptr query_cache_query;
} NET;

my_socket is defined as SOCKET, which was never defined (since never included winsock.h).
[16 May 2003 14:58] MySQL Verification Team
How I said before for to compile the server using the Visual Studio version
2000 it wans't necessary to change anything in the mysql.h

However if you are speaking about to compile a client application, you need
to put the below includes in the order showed, like our examples shows in the
binary distribution:

MyTest.c

#include        <windows.h>
#include	<stdio.h>
#include	<string.h>
#include	<mysql.h>

By the way, winsock.h is included in net_serv.cpp(27):

#ifdef __WIN__
#include <winsock.h>
#endif

Anyway if you continue with the problem, please inform what version you are
using of Visual Studio, for someone with the same version can confirm the
problem reported.
[17 May 2003 16:57] Adam Clauss
Sorry - wasn't being clear - yes, I am building a client application - with Visual Studio .NET (2002 - not the new 2003).

I had the necessary includes - but the problem, again, was in mysql.h.  It has the #include <winsock.h> in an ifdef __LCC__ which is NOT defined by VS.NET.  Therefore winsock never got included.

And the win32 distribution does not come with a "net_serv.cpp" that I can see.  Make sure we are talking about the same thing - I am talking about the Windows install.  It has a directory "include" which has all the necessary includes to create a client app.  This mysql.h is what contains the error.
[25 May 2003 12:01] Meng Wang
I have try in Visual Studio .NET 2003(with and without Intel C++ 7.1.0.11)can't work too.

VC.NET 2003 ::
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

Intel C++ ::
Intel(R) C++ Compiler for 32-bit applications, Version 7.1   Build 20030515Z
Copyright (C) 1985-2003 Intel Corporation.  All rights reserved.

and it's can working cygwin.

gcc@cygwin::

Reading specs from /usr/local/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs
Configured with: ./configure
Thread model: single
gcc version 3.3.1 20030519 (prerelease)
[26 May 2003 2:00] Meng Wang
#ifndef my_socket_defined
#ifdef __WIN__
#include <winsock.h> /**** included winsock.h ****/
#define my_socket SOCKET
#else
typedef int my_socket;
#endif /* __WIN__ */
#endif /* my_socket_defined */
#endif /* _global_h */

__LCC__ is for lcc C compiler system,
Win32 editor can find in::http://www.cs.virginia.edu/~lcc-win32/
[26 May 2003 5:02] MySQL Verification Team
Please take a look in the \examples\libmysqltes\mytest.dsw
Convert this project for Visual Studio .NET.
Below are the result at my side:

Build log was saved
at "file://c:\mysql\examples\libmysqltest\debug\BuildLog.htm"
myTest - 0 error(s), 1 warning(s)

For to avoid the error you got, take a look in the include order
at mytest.c:

#include        <windows.h>
#include	<stdio.h>
#include	<string.h>
#include	<mysql.h>