2012-07-29 58 views
1

那麼我的問題很簡單,我得到了以下包括:stdafx.h中和MySQL

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

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

,我得到的警告(這是非常煩人):

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' 

所以我檢查stdafx包括其中_WIN32_WINNT定義targetver.h,並my_global.h也包括_WIN32_WINNT,我能做些什麼呢?

這正是my_global.h文件至極的衝突的部分是MySQL C庫的一部分:

/* 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 

我一種新的關於這些問題包括,謝謝!

+0

從「my_global.h」中刪除定義?沒有理由兩次定義這個宏。 – jahhaj 2012-07-29 06:17:33

+0

但是,這將適用於my_global.h文件,如果我想在其他未定義_WIN32_WINNT的項目上使用它,將是一個問題。我認爲這不是一個優雅的解決方案,但它的一個大聲笑 – ffenix 2012-07-29 06:18:57

+0

引用自己早前的問題,「聽你的編譯器」。你被告知你需要知道的一切。它總會給你一個錯誤代碼參考,它可以在許多網站(MSDN)上查看。它也會在你的案例中引用'(24)'或'(195)'這一行,你很可能會推斷出你面臨的問題。 – ChiefTwoPencils 2012-07-29 06:19:43

回答

1

我建議my_global.h的以下修改,與

/* 
    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 

也許我失去了一些東西,但在MySQL的部分,我覺得確實挺可憐的替代

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

+0

你的解決方案完美的工作,我以前做過,但正如你所知我們談論的是一個圖書館而不是我製作的圖書館,它的MySQL圖書館和它的廣泛使用。因此,無論如何,我需要編輯這個文件,這種文件是由部分開發庫的MySQL人員吸引的。無論如何,謝謝:) – ffenix 2012-07-29 07:04:01

+0

@user - 你使用的是2008版的MySQL嗎?這是正確的版本嗎?當前的Windows SDK不支持Windows 2000,這可能是導致衝突的原因。 – 2012-07-29 10:28:14

0

瞭解問題後越好,似乎my_global.h設置您的Windows環境與MySQL使用。由於這種情況,我會停止使用targetver.h。我假設你正在使用預編譯頭文件,因爲這是唯一生成stdafx.h的時間。我會建議製作一個沒有預編譯頭文件或刪除targetver.h的項目。有關更多詳細信息,請參見here

+0

不是一個好的解決方案,因爲'my_global.h'附帶MySQL客戶端API,並且應該被視爲系統頭文件。這意味着OP不應該編輯它。 – 2012-07-29 06:25:54

+0

@JoachimPileborg:在更好地理解了這個問題之後,似乎OP不應該使用'targetver.h',因爲'my_global.h'包含了在Windows環境中工作的所有頭文件等。 – 2012-07-29 06:43:10

+0

我試着刪除預編譯頭文件 – ffenix 2012-07-29 06:47:17