简体   繁体   中英

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). 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++. You probably are using an mpi installation compiled with another C++ compiler. Compare output of mpicxx -v and 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.

I get this error when I build GCC on RHEL5 and then run it on RHEL7.

The underlying cause is the fixincludes mechanism in the GCC build. 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/ . Some of these headers from RHEL5 cause compilation errors on RHEL7, even after they are "fixed" by fixincludes .

My solution is simply to remove these headers from the include-fixed directory:

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

With these removed, my compilation errors disappear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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