【问题标题】:Unable to compile any C++ Code无法编译任何 C++ 代码
【发布时间】:2024-05-01 11:05:02
【问题描述】:

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

【问题讨论】:

  • 向我们展示您的编译语句...!即g++ x y z...
  • mpic++ -o Int_Any Integration_Any.cpp -lm(使用 MPI 和数学头文件)
  • 这绝对看起来您的安装有问题。您能否提供一些有关您正在使用的环境的详细信息?您能否尝试卸载并重新安装并描述您曾经执行此操作的命令?
  • 尝试创建一个脚本 - 在您添加到 PATH 前面的目录中将其命名为 g++,当调用它时会打印出它的参数;然后运气好的话,您将能够看到 mpic++ 实际编译的内容,您可以告诉我们....
  • mpic++ 或 g++ - 都给出相同的错误...

标签: c++ g++ ubuntu-12.04


【解决方案1】:

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

【讨论】: