简体   繁体   English

使用icpc进行编译-使用库

[英]Compiling with icpc - using libraries

I'm trying to compile a code that #includes the library 我正在尝试编译包含库的代码

In the code I have the following lines: 在代码中,我有以下几行:

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); 
}

When I compile using the following line: 当我使用以下行进行编译时:

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

I get the following errors: 我收到以下错误:

main.cpp(152): error: identifier "uniform_real_distribution" is undefined uniform_real_distribution<> U(0,1); main.cpp(152):错误:标识符“ uniform_real_distribution”是未定义的Uniform_real_distribution <> U(0,1); ^ ^

main.cpp(152): error: expected an expression uniform_real_distribution<> U(0,1); main.cpp(152):错误:预期一个表达式Uniform_real_distribution <> U(0,1); ^ ^

main.cpp(368): error: identifier "default_random_engine" is undefined default_random_engine generator; main.cpp(368):错误:标识符“ default_random_engine”是未定义的default_random_engine生成器; ^ ^

main.cpp(441): error: identifier "U" is undefined rr1=U(gen); main.cpp(441):错误:标识符“ U”未定义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); main.cpp(509):警告#1595:通过省略号rr1 = U(gen)传递的非POD(普通旧数据)类类型;

any idea how to resolve this? 任何想法如何解决这个问题?

This problem is caused by your Intel's compiler icpc version does not completely support c++11, which is actually c++0x. 此问题是由您的英特尔编译器icpc版本不完全支持c ++ 11(实际上是c ++ 0x)引起的。

That means: 这意味着:

  • You need to update your Intel's compiler to support uniform_real_distribution . 您需要更新您的英特尔编译器以支持uniform_real_distribution
  • Or using some library such as boost , PCG , etc. 或使用诸如boostPCG等的库。
  • Or still using c++11 way but without uniform_real_distribution. 或仍使用c ++ 11的方式,但没有统一的_real_distribution。 For example directly use mt19937 , mt19937_64 or any other pseudo-random generator. 例如,直接使用mt19937mt19937_64或任何其他伪随机数生成器。
  • Or using non-c++11 way ie rand() or rand_r() for nonserious use. 或使用非c ++ 11方式,即rand()或rand_r()进行非认真使用。

I guess the above part answered your question. 我想以上部分回答了您的问题。


Want to Know More? 想知道更多?

For Intel's user, you can check the compiler's compatibility by first and translate icc's version number into to a relative same gcc's version number and then check from c++0x/c++11 supported list 对于英特尔用户,您可以先检查编译器的兼容性,然后将icc的版本号转换为相对相同的gcc的版本号,然后从c ++ 0x / c ++ 11支持的列表中进行检查。

For GNU's user, you can check the compiler's compatibility directly from c++0x/c++11 supported list 对于GNU用户,您可以直接从c ++ 0x / c ++ 11支持的列表中检查编译器的兼容性。

for example, you can $icpc -v You may get something like icpc version abc (gcc version xyz compatibility) That means your Inter compiler's version is abc and its compatibility is as gcc version xyz 例如,您可以$icpc -v您可能会得到类似icpc version abc (gcc version xyz compatibility)这意味着您的Inter编译器版本为abc,其兼容性为gcc版本xyz

And since uniform_real_distribution is not supported till GCC 4.4.5 ? 而且由于在GCC 4.4.5之前支持uniform_real_distribution (GCC 4.4.7 is verified support) (已验证GCC 4.4.7支持)

Then if your xyz is later than 4.4.5?(4.4.7 for sure) you can use 'uniform_xxx_distribution' function families without compatibility issues. 然后,如果您的xyz晚于4.4.5?(肯定是4.4.7),则可以使用“ uniform_xxx_distribution”函数族,而不会出现兼容性问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM