简体   繁体   中英

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

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.

That means:

  • You need to update your Intel's compiler to support uniform_real_distribution .
  • Or using some library such as boost , PCG , etc.
  • Or still using c++11 way but without uniform_real_distribution. For example directly use mt19937 , mt19937_64 or any other pseudo-random generator.
  • Or using non-c++11 way ie rand() or rand_r() for nonserious use.

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

For GNU's user, you can check the compiler's compatibility directly from c++0x/c++11 supported list

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

And since uniform_real_distribution is not supported till GCC 4.4.5 ? (GCC 4.4.7 is verified support)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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