1

Well my problem is pretty simple, i got the following includes:

#include "stdafx.h"
#include "my_global.h"
#include "mysql.h"
#include "ServerManager.h"
#include "GamePlay.h"

#pragma comment(lib, "libmysql.lib")

And i get the WARNING (which is pretty annoying):

1>c:\program files\mysql\connector c 6.0.2\include\config-win.h(24): warning C4005: '_WIN32_WINNT' : macro redefinition
1>          c:\program files\windows kits\8.0\include\shared\sdkddkver.h(195) : see previous definition of '_WIN32_WINNT'

So i check stdafx includes targetver.h where _WIN32_WINNT is defined, and my_global.h includes also _WIN32_WINNT, what can i do about this?

This is exactly the conflicting part of my_global.h file wich is part of the MySQL C library:

/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/* Defines for Win32 to make it compatible for MySQL */

#define BIG_TABLES

/* 
  Minimal version of Windows we should be able to run on.
  Currently Windows 2000
*/
#define _WIN32_WINNT     0x0500

I am kind of new regarding those including problems, thanks !

ffenix
  • 543
  • 1
  • 5
  • 22
  • Remove the definition from "my_global.h"? No reason to define this macro twice. – jahhaj Jul 29 '12 at 06:17
  • But this will apply to my_global.h file and if i want to use it on other proyect where i havent defined _WIN32_WINNT, will be a problem. I think thats not an elegant solution, but its one lol – ffenix Jul 29 '12 at 06:18
  • Quoting myself from an earlier question, "Listen to your compiler". You're told everything you need to know. It will always give you an error code reference, which can be viewed on many sites(MSDN). It also will reference the line, `(24)` or `(195)` in your case, and you can most likely deduce the problem you're facing. – ChiefTwoPencils Jul 29 '12 at 06:19
  • OK, so you've defined _WIN32_WINNT in my_global.h with one value because you are targeting some version of Windows, but now you are trying to use that header in a project that is targeting another version of Windows. How do you expect that to work? You need to think about what you are trying to accomplish. – jahhaj Jul 29 '12 at 06:21
  • But like i say before, is there any other method to make this look more elegant? i dont want to remove the _WIN32_WINNT declaration from my_global.h – ffenix Jul 29 '12 at 06:21
  • I see your point, problem is i didn't make it, it is part of the MySQL C library so i feel kind of bad editing the file, it have a reason to be there and its a file i will use in many projects, where i might not use pre compiled headers. – ffenix Jul 29 '12 at 06:23
  • @jahhaj The header file `my_global.h` is part of the API, and therefore should not be modified. – Some programmer dude Jul 29 '12 at 06:24
  • Have you modified `stdafx.h` anything yourself? If not then I suggest you try to make a minimal example and include that to make a bug-report to the MySQL developers. Remember to include all details you could think of, e.g. the version of Visual Studio, service packs, SDK version, etc. – Some programmer dude Jul 29 '12 at 06:30
  • OK, I see that now. The name my_global.h suggested to me that the OP had written it. – jahhaj Jul 29 '12 at 06:30
  • To me this is poor coding by MySQL. Despite it being a library header in this case I would modify it. If the OP could post the code from my_global.h then maybe someone will be able to suggest a sensible modification. – jahhaj Jul 29 '12 at 06:37
  • i updated the post with the conflicting part – ffenix Jul 29 '12 at 06:51

2 Answers2

1

I would suggest the following modification of my_global.h, replace

/* 
  Minimal version of Windows we should be able to run on.
  Currently Windows 2000
*/
#define _WIN32_WINNT     0x0500

with

/* 
  Minimal version of Windows we should be able to run on.
  Currently Windows 2000
*/
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500
#error "MySQL requires Windows 2000 or later"
#elif !defined(_WIN32_WINNT)
#define _WIN32_WINNT     0x0500
#endif

Maybe I'm missing something but really quite poor on the part of MySQL I think.

jahhaj
  • 3,021
  • 1
  • 15
  • 8
  • Your solution works perfectly, i have done that before, but as you know we talking about a library and not a library i made, its MySQL library and its widely used. So in anyway i need to edit the file which kind of sucks by part of MySQL guys that develop the library. Thanks anyway :) – ffenix Jul 29 '12 at 07:04
  • @user - Are you using the 2008 edition of MySQL? Is that the correct version? Current Windows SDKs do not support Windows 2000, which might be a cause for the conflict. – Bo Persson Jul 29 '12 at 10:28
0

After understanding the problem better, it seems my_global.h sets up your windows environment to be used with MySQL. Since this is the case I would stop using targetver.h. I'm assuming you are using precompiled headers because that is the only time stdafx.h is generated. I would suggest making a project without precompiled headers or removing targetver.h. See here for more details.

Community
  • 1
  • 1
Jesse Good
  • 50,901
  • 14
  • 124
  • 166
  • Not a good solution, as `my_global.h` comes with the MySQL client API, and should be considered a system header file. Which means the OP should not really edit it. – Some programmer dude Jul 29 '12 at 06:25
  • @JoachimPileborg: After understanding the question better, it seems the OP shouldn't use `targetver.h` since `my_global.h` includes all the headers, etc. for working in a windows environment. – Jesse Good Jul 29 '12 at 06:43
  • Ill try removing precompiled headers – ffenix Jul 29 '12 at 06:47
  • I cant remove the precompiled headers, since windows.h includes sdkddkver.h wich already have the declaration of _WIN32_WINNT... So i guess the only option is to remove it from MySQL library. – ffenix Jul 29 '12 at 06:49
  • @user1175832: But `my_global.h` already includes `windows.h` for you. – Jesse Good Jul 29 '12 at 06:51
  • This is very poor design by MySQL since if i reeplace my_global.h for windows.h, is assuming that mine windows version is Windows 2000 or at least that is the new message my compiler is giving me since i cant use API InetPton which works in base of _WIN32_WINNT so in any case i need to edit the my_global.h header. :/ – ffenix Jul 29 '12 at 07:02