簡體   English   中英

編譯一個簡單的C++程序時出現的問題

[英]A problem when compiling a simple C++ program

當我編譯這樣一個簡單的 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++

這里已經存在可能的解決方案

只需將 -std=c++11 更改為 -std=gnu++11

最后,我解決了這個問題。 這個問題的原因是我安裝了codeblocks

codeblocks將環境變量添加到我的計算機,例如C_INCLUDEDE_PATHCPLUS_INCLUDE_PATHLIBRARY_PATH 當我刪除這些環境變量時,問題就解決了。

暫無
暫無

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

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