简体   繁体   English

由于“'isblank'未在此范围内声明”错误,Mingw无法编译

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

I try to compile & link the following program with mingw. 我尝试使用mingw编译和链接以下程序。 When I use the default version it works well. 当我使用默认版本时,它运行良好。 But when I use c++11 version it doesn't compile and gives me the following error newfile.cpp:22:18: error: 'isblank' was not declared in this scope . 但是,当我使用c ++ 11版本时,它不会编译并给我以下错误newfile.cpp:22:18: error: 'isblank' was not declared in this scope for testing the following program it's enough to call the _isblank function in main. 为了测试以下程序,它足以在main中调用_isblank函数。

For compiling the Netbeans 8.0.2 uses 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 . 对于编译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

The mingw version is 4.8.1 and everything is configured well(Default). mingw版本是4.8.1并且一切都配置良好(默认)。

I tried by adding/removing namespace std. 我尝试添加/删除命名空间std。 The problem seems to be in cctype header! 问题似乎是在cctype标题! But I wonder how to solve it. 但我想知道如何解决它。 The project will have to be compiled with g++ on linux! 该项目必须在linux上用g ++编译! Will these problems remain? 这些问题会继续吗?

#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';
}

In my version of GNU library the declaration of isblank in <ctype.h> header is protected by some conditional compilation directives, which nevertheless should make this function available in C++. 在我的GNU库版本中, <ctype.h>头文件中isblank的声明受到一些条件编译指令的保护,但这些指令应该使这个函数在C ++中可用。

However, in <cctype> header this function is is separated from all other declarations and given a special treatment for some reason. 但是,在<cctype>标头中,此函数与所有其他声明分开,并由于某种原因给予特殊处理。 It is only made available in namespace std if macro _GLIBCXX_USE_C99_CTYPE_TR1 is defined. 如果定义了宏_GLIBCXX_USE_C99_CTYPE_TR1它仅在命名空间std可用。 This is what it looks like inside <cctype> 这就是<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

I don't know what the purpose that _GLIBCXX_USE_C99_CTYPE_TR1 macro is supposed to serve. 我不知道_GLIBCXX_USE_C99_CTYPE_TR1宏应该服务的目的是什么。 In my GCC installation this macro is defined, which makes isblank available in my case. 在我的GCC安装中,定义了这个宏,这使我的情况下可以使用isblank

You might want to check what your <cctype> looks like and see if something like that is happening on your side as well. 您可能想要检查<cctype>外观,看看是否还有类似的情况。

It worked when I undefined STRICT_ANSI in the translation unit adding -U__STRICT_ANSI__ to the compiler options. 当我在转换单元中未定义STRICT_ANSI时 ,它将-U__STRICT_ANSI__添加到编译器选项中。 But I wonder which part of my program violates C++ standards. 但我想知道我的程序的哪一部分违反了C ++标准。

It should have been compiled in this way: 应该以这种方式编译:

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