Ubuntu 上的 g++ 4.8.1 无法编译大型位集 [英] g++ 4.8.1 on Ubuntu can't compile large bitsets

查看:28
本文介绍了Ubuntu 上的 g++ 4.8.1 无法编译大型位集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的来源:

#include <iostream>
#include <bitset>

using std::cout;
using std::endl;

typedef unsigned long long U64;
const U64 MAX = 8000000000L;

struct Bitmap
{
  void insert(U64 N) {this->s.set(N % MAX);}
  bool find(U64 N) const {return this->s.test(N % MAX);}
private:
  std::bitset<MAX> s;
};

int main()
{
  cout << "Bitmap size: " << sizeof(Bitmap) << endl;
  Bitmap* s = new Bitmap();
  // ...
}

编译命令及其输出:

g++ -g -std=c++11 -O4  tc002.cpp -o latest 
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.

错误报告及其修复需要很长时间... 有人遇到过这个问题吗?我可以操作一些编译器标志或其他东西(可能在源代码中)来绕过这个问题吗?

Bug report and its fix will take long time... Has anybody had this problem already? Can I manipulate some compiler flags or something else (in source probably) to bypass this problem?

我在 Ubuntu 上编译,它实际上是具有 12GB 内存和 80GB 磁盘空间的 VMware 虚拟机,主机是 MacBook Pro:

I'm compiling on Ubuntu, which is actually VMware virtual machine with 12GB memory and 80GB disk space, and host machine is MacBook Pro:

uname -a
Linux ubuntu 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

推荐答案

在我的机器上,g++ 4.8.1 最多需要大约 17 GB 的 RAM 来编译这个文件,正如使用 top 观察到的那样.

On my machine, g++ 4.8.1 needs a maximum of about 17 gigabytes of RAM to compile this file, as observed with top.

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
18287 nm        20   0 17.880g 0.014t    808 D  16.6 95.7   0:17.72 cc1plus

RES 列中的

't' 代表 TB ;)

't' in the RES column stands for terabytes ;)

所用时间为

real    1m25.283s
user    0m31.279s
sys     0m5.819s

在 C++03 模式下,g++ 编译同一个文件只使用几兆字节.所用时间为

In the C++03 mode, g++ compiles the same file using just a few megabytes. The time taken is

real    0m0.107s
user    0m0.074s
sys     0m0.011s

我会说这绝对是一个错误.一种解决方法是为机器提供更多 RAM,或启用交换.或者使用clang++.

I would say this is definitely a bug. A workaround is to give the machine more RAM, or enable swap. Or use clang++.

这篇关于Ubuntu 上的 g++ 4.8.1 无法编译大型位集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆