PCL與MFC結合的衝突
系統:windows 10
PCL版本:pcl 1.8.1
VS版本:vs2015(vc14)
1. error C2589: “(”: “::”右邊的非法標記 、error C2059: 語法錯誤 : “::”
MFC程序過程中,PCL使用STL一些類編譯出錯,放到Console Application裏一切正常。
比如出現如下錯誤:
pcl_visualizer.hpp(1429): error C2059: syntax error: '::'
pcl_visualizer.hpp(1429): error C2589: '(': illegal token on right side of '::'
定位問題位置:
minmax[0] = std::numeric_limits<double>::min ();
錯誤原因:
關於max、min的問題是 PCL 使用 STL 中 max、min 函數與 MFC 中 minwindef 定義的宏 max、min 衝突。
解決辦法:
1. 設置項目屬性,在預定義處理器中添加定義NOMINMAX來禁止使用Vsual C++的min/max宏定義。
項目屬性 --> C/C++ --> 預處理器 ——> 預處理器定義 (此處添加預定義編譯開關 NOMINMAX)注意!!!一定要加在第一個上面。
2. 在每個出錯的地方加上括號,與Vsual C++的min/max宏定義區分開(我採用的這種方法)
minmax[0] = (std::numeric_limits<double>::min)();
若自己寫的出錯,如
size.Width = std::max(size.Width, elementSize.Width);
修改爲:
size.Width = (std::max)(size.Width, elementSize.Width);
3.對於使用了Windef文件的AtlImage.h 和GDIPlus.h,直接對裏面的max() min()函數進行替換;或者 在使用到 max() min()函數 的頭文件定義後面添加:
#ifdef max
#define max(a,b) FUN....
#endif
這第三種解決法我也沒弄懂,參考:
max 宏定義取消:error C2589: error C2059: 語法錯誤 : “::”
2. error C2661: “operator new” : 沒有重載函數接受 3 個參數
錯誤原因:
對於mfc與pcl的各種衝突,例如其上。
解決方法:
作者直接註銷了,dlg裏面的#define new DEBUG_NEW
也可參考:http://bbs.csdn.net/topics/330096920
#ifdef _DEBUG
//#define new DEBUG_NEW //wishchin 爲消除pcl不能拿new三個參數!!!
#endif
3.error C3861: ‘RGB’: identifier not found
ClassView.cpp(316): error C3861: 'RGB': identifier not found
錯誤原因:
PCL 中的RGB結構與MFC中的RGB宏衝突問題。PCL在定義struct RGB時進行了 RGB宏的檢測 如果檢測到了RGB宏就將其取消,導致MFC中使用的RGB沒有定義。這在對話框程序中不會出現,在基於vc框架的單文檔中出現,因爲MFC嚮導自建的對話框類中會用到RGB宏。
解決方法:
目前我也沒有什麼好方法解決,只是註釋掉了MFC用到RGB的地方,求大神給與解決。