2013-03-07 41 views
3

我正在使用兩個獨立的庫的Qt平臺。我面臨的問題是他的兩個庫對int32_t有不同的聲明。第三方庫衝突的定義/ redefinitons

的第一庫具有:

#ifdef _WIN32 
#if ULONG_MAX == 0xffffffff 
typedef long int32_t; 
#else 
typedef int int32_t; 
#endif 
#endif 

第二圖書館:

typedef signed __int32 int32_t; 
typedef unsigned __int32 uint32_t; 

,我得到的錯誤是:

C:\Program Files (x86)\SiliconSoftware\Runtime5.1\include\msinttypes\stdint.h:91: error: C2371: 'int32_t' : redefinition; different basic types c:\program files (x86)\matlab\r2008a\extern\include\mclmcr.h:216: see declaration of 'int32_t'

我嘗試下面這個職位上計算器:

Typedef redefinition (C2371) for uint32 in two 3rd-party libraries

,我試圖實現它在我的代碼:

#define int32_t VicTorv3_int32_t 
#include"mclmcr.h" 
#undef int32_t 
#define int32_t Silicon_int32_t 
#include "stdint.h" 
#undef int32_t 

我仍然得到同樣的錯誤。請幫忙。

回答

2

stdint.h也是一個系統包含文件。在define/undef解決方法之前包含的機會很好。當你的解決方法試圖再次包含該文件時,包容衛士會完成他們的工作。你可以用下面的方法檢查一下情況: Displaying the #include hierarchy for a C++ file in Visual Studio

我建議在包含stdint.h的地方將文件的頂部移動到文件的最頂部,然後再包含所有其他文件。

注意,系統包含文件stdint.h與其他版本的問題會產生問題。