Unable to compile any C++ Code
Asked Answered
C

2

6

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);
                             ^
Clyde answered 13/11, 2014 at 3:22 Comment(7)
Show us your compile statement...! i.e. g++ x y z...Helvetic
mpic++ -o Int_Any Integration_Any.cpp -lm (using MPI with math header file)Clyde
This definitely looks like there is something wrong with your installation. Can you provide some details of what environment you are using? Can you try to uninstall and reinstall again and describe what commands you used to do that?Association
try creating a script - name it g++ in a directory you add to the front of your PATH, that when called prints out its arguments; then with a little luck you'll be able to see what mpic++ is actually doing to compile, and you can tell us....Helvetic
mpic++ or g++ - both give the same error...Clyde
do you have mpi 64 bits?Gerta
yes - it was working fine before..Clyde
S
1

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.

Sororate answered 20/1, 2022 at 17:13 Comment(0)
K
0

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.

Kohlrabi answered 3/3, 2017 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.