簡體   English   中英

由於“'isblank'未在此范圍內聲明”錯誤,Mingw無法編譯

[英]Mingw doesn't compile due to “'isblank' was not declared in this scope” error

我嘗試使用mingw編譯和鏈接以下程序。 當我使用默認版本時,它運行良好。 但是,當我使用c ++ 11版本時,它不會編譯並給我以下錯誤newfile.cpp:22:18: error: 'isblank' was not declared in this scope 為了測試以下程序,它足以在main中調用_isblank函數。

對於編譯Netbeans 8.0.2使用g++ -c -g -Wall -std=c++11 -MMD -MP -MF "build/Debug/MinGW_1-Windows/newfile.od" -o build/Debug/MinGW_1-Windows/newfile.o newfile.cpp

mingw版本是4.8.1並且一切都配置良好(默認)。

我嘗試添加/刪除命名空間std。 問題似乎是在cctype標題! 但我想知道如何解決它。 該項目必須在linux上用g ++編譯! 這些問題會繼續嗎?

#include <cstdlib>
#include <cctype>
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
#include <map>
#include <functional>
#include "newfile.h"

using namespace std;
conf_info_t CONF_INFO;

#define CONF_FILE_ADDRESS "confs.txt"
//
//typedef std::map<std::string, std::function<void (const std::string&)>> confMap_t;
//confMap_t confMap;

int _isblank(int c){
    return isblank(c);
    //return c == ' ' || c == '\t';
}

在我的GNU庫版本中, <ctype.h>頭文件中isblank的聲明受到一些條件編譯指令的保護,但這些指令應該使這個函數在C ++中可用。

但是,在<cctype>標頭中,此函數與所有其他聲明分開,並由於某種原因給予特殊處理。 如果定義了宏_GLIBCXX_USE_C99_CTYPE_TR1它僅在命名空間std可用。 這就是<cctype>里面的樣子

#if __cplusplus >= 201103L

#ifdef _GLIBCXX_USE_C99_CTYPE_TR1

#undef isblank

namespace std
{
  using ::isblank;
} // namespace std

#endif // _GLIBCXX_USE_C99_CTYPE_TR1

#endif // C++11

我不知道_GLIBCXX_USE_C99_CTYPE_TR1宏應該服務的目的是什么。 在我的GCC安裝中,定義了這個宏,這使我的情況下可以使用isblank

您可能想要檢查<cctype>外觀,看看是否還有類似的情況。

當我在轉換單元中未定義STRICT_ANSI時 ,它將-U__STRICT_ANSI__添加到編譯器選項中。 但我想知道我的程序的哪一部分違反了C ++標准。

應該以這種方式編譯:

g++ -U__STRICT_ANSI__   -c -g -Wall -std=c++11 -MMD -MP -MF "build/Debug/MinGW_1-Windows/main.o.d" -o build/Debug/MinGW_1-Windows/main.o main.cpp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM