简体   繁体   English

无法编译任何 C++ 代码

[英]Unable to compile any C++ Code

Whenever I try to compile a C++ file with IOStream , I get this error.. I've tried reinstalling GCC G++ (both 4.6 and 4.9) AND cpp.. It hasnt helped (or maybe I didnt do it the right way).每当我尝试使用 IOStream 编译 C++ 文件时,我都会收到此错误。我尝试重新安装 GCC G++(4.6 和 4.9)和 cpp 。它没有帮助(或者我没有以正确的方式进行操作)。 How do I fix this error如何解决此错误

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);
                             ^

I saw the same error using openmpi and a newer version of g++.我在使用 openmpi 和更新版本的 g++ 时看到了同样的错误。 You probably are using an mpi installation compiled with another C++ compiler.您可能正在使用由另一个 C++ 编译器编译的 mpi 安装。 Compare output of mpicxx -v and g++ -v.比较 mpicxx -v 和 g++ -v 的输出。 I guess mpicxx -v will display an older g++ version, than you have and reinstall your mpi with the newer g++ version you are using.我猜 mpicxx -v 将显示比您拥有的更旧的 g++ 版本,并使用您正在使用的新 g++ 版本重新安装您的 mpi。

I get this error when I build GCC on RHEL5 and then run it on RHEL7.当我在 RHEL5 上构建 GCC 然后在 RHEL7 上运行它时,我得到了这个错误。

The underlying cause is the fixincludes mechanism in the GCC build.根本原因是 GCC 构建中的fixincludes机制。 This copies (and modifies) various headers from /usr/include on the build system to <prefix>/lib/gcc/x86_64-pc-linux-gnu/<version>/include-fixed/ .这会将构建系统上/usr/include中的各种标头复制(并修改)到<prefix>/lib/gcc/x86_64-pc-linux-gnu/<version>/include-fixed/ Some of these headers from RHEL5 cause compilation errors on RHEL7, even after they are "fixed" by fixincludes .来自 RHEL5 的这些头文件中的一些会导致 RHEL7 上的编译错误,即使它们已被fixincludes “修复”。

My solution is simply to remove these headers from the include-fixed directory:我的解决方案只是从include-fixed目录中删除这些标头:

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

With these removed, my compilation errors disappear.删除这些后,我的编译错误就消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM