#define WIN32_LEAN_AND_MEAN 的做用

[轉]#define WIN32_LEAN_AND_MEAN 的做用

今天看了用mysql的庫+vc鏈接數據庫,結果我用mfc application嚮導創建一個工程,而後添加#include "mysql.h"(已經設置好了環境),編譯出現了一大堆錯誤,以下mysql

Compiling...
StdAfx.cpp
c:mysqlincludemysql_com.h(116) : error C2146: syntax error : missing ';' before identifier 'fd'
c:mysqlincludemysql_com.h(116) : error C2501: 'SOCKET' : missing storage-class or type specifiers
c:mysqlincludemysql_com.h(116) : error C2501: 'fd' : missing storage-class or type specifiers
c:mysqlincludemysql_com.h(180) : error C2065: 'SOCKET' : undeclared identifier
c:mysqlincludemysql_com.h(180) : error C2146: syntax error : missing ')' before identifier 's'
c:mysqlincludemysql_com.h(181) : error C2059: syntax error : ')'
Error executing cl.exe.c++

 

網上找了許久,沒有找到答案,我就查看了mysql根目錄下的examples,裏面有個工程是否是用 c++編寫的,我調試了一下,竟然能夠編譯,我就想mysql.h這個文件不會有錯誤,應該是編譯時,include 衝突了,我就把stdafx.h那個文件刪除掉幾行,結果當我把#define WIN32_LEAN_AND_MEAN這幾話屏蔽後,就能夠編譯了,我也試用了 mysql_init((MYSQL*) 0);這個函數沒有問題.因此問題就出在define WIN32_LEAN_AND_MEAN這句話.sql

#define WIN32_LEAN_AND_MEAN,這句的目的是指示編譯器不要包含與MFC相關的操做。( 只是一個好的練習——若是你不在使用 MFC) 而後咱們包括 dxutil.h 和 ddutil.h,這是兩個頗有用的頭文件。 他們可以使你以一種比一般的DirectX編程更輕鬆的方式來工做。數據庫

 

爲何要  #define WIN32_LEAN_AND_MEAN 。編程

   答案很簡單,由於我要包含儘可能精簡的內容,包含了這一句編譯的時候明顯快多了。app

相關文章
相關標籤/搜索