Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
                             ^
like image 340
Prateek Narendra Avatar asked Nov 22 '22 08:11

Prateek Narendra


1 Answers

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.

like image 200
Nemo Avatar answered Dec 05 '22 09:12

Nemo