gsp:
MinGW Developer Studio 2.05使用g++編譯器版本是mingw-gcc-3.3.1
Dev-C++ 4.9.9.2用的g++編譯器版本可能是mingw-gcc-3.4.2
Linux安裝的是Gcc4.3.2(20070920)
案例一:Hx
用Dev編譯class template報錯,改用MinGW之後編譯通過。
案例二:Gsp
用c語言寫程序模仿UNIX環境中bc命令的基本功能,其中我用到數學函數sin,cos,#include
,還用到了判斷空白字元的函數isblank和isspace。
情況如下:
KDE編譯:sin和cos未定義
Dev編譯:通過
Mingw編譯:isspace未定義
解決:
KDE:百度之後,在編譯選項中加入-lm,鏈接數學庫后通過。對於數學庫其他編譯器默認都鏈接了。
Mingw:沒辦法,只好用isblank替換isspace。
案例三:Gsp
Gcc不同版本之間的差異
下面的代碼片段:
void LogAnalyse::StopAnalyse() { INETH.close(); } void LogAnalyse::Initialize() { FileOpen(INETH, ineth.c_str(), std::fstream::in); } void LogAnalyse::FileOpen(fstream& file, const char* name, std::_Ios_Openmode flag) { if (file) file.close(); file.open(name, std::fstream::in); if (!file) cerr << "Error: unable to open file " << name <<"\n"; } |
註:INETH是類LogAnalyse的成員變數,一個fstream對象。
運行時的調用順序是Initialize()->StopAnalyse()->Initialize(),文件INETH打開,關閉,再打開。
現象:用gcc4.3.2(20070920)編譯后運行正常,在另一台電腦用gcc3.4.6(20060420)編譯運行,打開關閉正常,再打開就出現錯誤Error: unable to open file...
解決:把代碼
if (!file) cerr << "Error: unable to open file " << name <<"\n"; |
改為
if (file == NULL) cerr << "Error: unable to open file " << name <<"\n"; |
運行正常。