繁体   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