编译简单的C ++程序时出现问题

时间:2019-07-28 09:45:23

标签: c++ compiler-errors mingw

当我编译这样的简单c ++程序时

#include<iostream>
using namespace std;
int main()
{
    cout << "hello word" << endl;
    return 0;
}

我收到一些错误消息, 这是错误消息的一部分:

In file included from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\cstdlib:75,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ext\string_conversions.h:41,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\basic_string.h:6391,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\string:52,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\locale_classes.h:40,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\ios_base.h:41,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:42,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
                 from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
                 from F:\Desktop\web\web\work_one\test.cpp:1:
e:\mingw\include\stdlib.h:90:1: error: '_BEGIN_C_DECLS' does not name a type
 _BEGIN_C_DECLS
 ^~~~~~~~~~~~~~
e:\mingw\include\stdlib.h:363:1: error: '__CRT_ALIAS' does not name a type
 __CRT_ALIAS __cdecl __MINGW_NOTHROW
 ^~~~~~~~~~~
e:\mingw\include\stdlib.h:367:1: error: '__CRT_ALIAS' does not name a type
 __CRT_ALIAS __cdecl __MINGW_NOTHROW
 ^~~~~~~~~~~
e:\mingw\include\stdlib.h:444:55: error: '_locale_t' has not been declared
 __int64 _wcstoi64_l(const wchar_t *, wchar_t **, int, _locale_t);
                                                       ^~~~~~~~~
e:\mingw\include\stdlib.h:447:65: error: '_locale_t' has not been declared
 unsigned __int64 _wcstoui64_l(const wchar_t *, wchar_t **, int, _locale_t);
                                                                 ^~~~~~~~~
e:\mingw\include\stdlib.h:866:1: error: '_END_C_DECLS' does not name a type
 _END_C_DECLS
 ^~~~~~~~~~~~

这似乎与头文件语法有关?但是我没有修改头文件。

我使用此命令进行编译

g++ -g -std=c++11 F:\Desktop\web\web\work_one\test.cpp -o test.exe

我的操作系统是Win10

g ++版本为g ++(MinGW.org GCC-8.2.0-3)8.2.0

我从http://www.mingw.org/那里获得的G ++

2 个答案:

答案 0 :(得分:0)

可能的解决方案已经存在here

只需将-std = c ++ 11更改为-std = gnu ++ 11

答案 1 :(得分:0)

最后,我解决了这个问题。出现此问题的原因是我安装了codeblocks

codeblocks向我的计算机添加环境变量,例如C_INCLUDEDE_PATHCPLUS_INCLUDE_PATHLIBRARY_PATH。当我删除这些环境变量时,问题已解决。