gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:45:47 30 4
gpt4 key购买 nike

我正在尝试编译#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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com