簡體   English   中英

無法編譯任何 C++ 代碼

[英]Unable to compile any C++ Code

每當我嘗試使用 IOStream 編譯 C++ 文件時,我都會收到此錯誤。我嘗試重新安裝 GCC G++(4.6 和 4.9)和 cpp 。它沒有幫助(或者我沒有以正確的方式進行操作)。 如何解決此錯誤

In file included from /usr/include/c++/4.9/bits/localefwd.h:40:0,
             from /usr/include/c++/4.9/ios:41,
             from /usr/include/c++/4.9/ostream:38,
             from /usr/include/c++/4.9/iostream:39,
             from Integration_Any.cpp:1:
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:52:23: error:‘uselocale’was         not declared in this scope
   extern "C" __typeof(uselocale) __uselocale;
                   ^
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:52:45: error: invalid type in    declaration before ‘;’ token
   extern "C" __typeof(uselocale) __uselocale;
                                         ^
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h: In function ‘int     std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’:       /usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:75:53: error:     ‘__gnu_cxx::__uselocale’ cannot be used as a function
     __c_locale __old = __gnu_cxx::__uselocale(__cloc);
                                                 ^
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:100:33: error:     ‘__gnu_cxx::__uselocale’ cannot be used as a function
     __gnu_cxx::__uselocale(__old);
                             ^

我在使用 openmpi 和更新版本的 g++ 時看到了同樣的錯誤。 您可能正在使用由另一個 C++ 編譯器編譯的 mpi 安裝。 比較 mpicxx -v 和 g++ -v 的輸出。 我猜 mpicxx -v 將顯示比您擁有的更舊的 g++ 版本,並使用您正在使用的新 g++ 版本重新安裝您的 mpi。

當我在 RHEL5 上構建 GCC 然后在 RHEL7 上運行它時,我得到了這個錯誤。

根本原因是 GCC 構建中的fixincludes機制。 這會將構建系統上/usr/include中的各種標頭復制(並修改)到<prefix>/lib/gcc/x86_64-pc-linux-gnu/<version>/include-fixed/ 來自 RHEL5 的這些頭文件中的一些會導致 RHEL7 上的編譯錯誤,即使它們已被fixincludes “修復”。

我的解決方案只是從include-fixed目錄中刪除這些標頭:

features.h
pthread.h
wchar.h
sys/stat.h
bits/string2.h

刪除這些后,我的編譯錯誤就消失了。

暫無
暫無

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

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