c++ - 使用 icpc 编译 - 使用库

标签 c++ icc

我正在尝试编译#includes 库的代码

在代码中我有以下几行:

int main()
{
    clock_t begin = clock();
    random_device rd;
    mt19937 gen(rd());
    uniform_real_distribution<> U(0,1);
    default_random_engine generator;
    rr1=U(gen); 
}

当我使用以下行进行编译时:

 icpc  -std=c++0x -std=c++11 -o main main.cpp -O3

我收到以下错误:

main.cpp(152): error: identifier "uniform_real_distribution" is undefined uniform_real_distribution<> U(0,1); ^

main.cpp(152): error: expected an expression uniform_real_distribution<> U(0,1); ^

main.cpp(368): error: identifier "default_random_engine" is undefined default_random_engine generator; ^

main.cpp(441): error: identifier "U" is undefined rr1=U(gen); // first random number for time interval

main.cpp(509): warning #1595: non-POD (Plain Old Data) class type passed through ellipsis rr1=U(gen);

知道如何解决这个问题吗?

最佳答案

这个问题是因为你的Intel的编译器icpc版本没有完全支持c++11,其实就是c++0x。

这意味着:

  • 您需要更新您的 Intel 编译器以支持 uniform_real_distribution
  • 或者使用一些库,例如 boost , PCG
  • 或者仍然使用 c++11 方式但没有 uniform_real_distribution。例如直接使用 mt19937 , mt19937_64 或任何其他伪随机生成器。
  • 或使用非 C++11 方式,即 rand() 或 rand_r() 用于非严肃用途。

我猜上面的部分回答了你的问题。


想了解更多?

对于Intel的用户,可以先检查编译器的兼容性,将icc的版本号翻译成相对相同的gcc的版本号,然后从c++0x/c++11 supported list中查看。

对于 GNU 用户,您可以直接从 c++0x/c++11 supported list 检查编译器的兼容性。

例如,您可以 $icpc -v 你可能会得到类似的东西 icpc 版本 a.b.c(gcc 版本 x.y.z 兼容性) 这意味着您的 Inter 编译器的版本是 a.b.c 并且它的兼容性是 gcc 版本 x.y.z。

并且由于 uniform_real_distributionGCC 4.4.5 之前 受支持? (GCC 4.4.7 已验证支持)

那么如果你的 x.y.z 晚于 4.4.5?(肯定是 4.4.7)你可以使用 'uniform_xxx_distribution' 函数系列而不会出现兼容性问题。

关于c++ - 使用 icpc 编译 - 使用库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38951081/

相关文章:

C++ 检查函数的两个版本

c++ - 外部类函数

c++立陶宛语,如何获得比ascii更多的内容

c++ - 帮助我开始(流量操纵)

c++ - clang 的全局构造函数警告是否过于严格?

c++ - 英特尔 C/C++ 编译器在数组初始化期间抛出错误

windows - 如何在 Windows 上通过 Python 以编程方式为 CMake 配置编译器?

c++ - 在调用时仅指定一些模板参数

ISO 8601 :2004 中的 C 预处理器 __TIMESTAMP__

c++ - 转换 Derived** → Base** 是错误的吗?还有什么选择?