无法编译任何C++代码

Unable to compile any C++ Code

本文关键字:C++ 代码 任何 编译      更新时间:2023-10-16

每当我试图用IOStream编译C++文件时,我都会收到这个错误。。我试着重新安装GCC G++(4.6和4.9)and 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);
                             ^

当我在RHEL5上构建GCC,然后在RHEL7上运行它时,会出现此错误。

根本原因是GCC构建中的fixincludes机制。这将从生成系统上的/usr/include复制(并修改)各种标头到<prefix>/lib/gcc/x86_64-pc-linux-gnu/<version>/include-fixed/。来自RHEL5的这些报头中的一些在RHEL7上引起编译错误;固定的";通过CCD_ 4。

我的解决方案只是从include-fixed目录中删除这些头:

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

删除这些之后,我的编译错误就消失了。

我在使用openmpi和更新版本的g++时看到了同样的错误。您可能使用的是使用另一个C++编译器编译的mpi安装。比较mpicxx-v和g++-v的输出。我猜mpicxx-v将显示一个比你旧的g++版本,并用你正在使用的新g++版本重新安装你的mpi。