Why random header not importing

2019-01-20 20:29发布

问题:

I have written code in C++ and compiled it by typing make. An error occurs:

/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

回答1:

you need to add "-std=c++11" to your compiler arguments, telling it that it is a C++11 compile

$ g++ -std=c++11 your_file.cpp -o your_program

If you are using some IDE, you need to search the documentation to find out how to add this line so the compiler knows.



回答2:

The random library is using a newer version of the C++ standard (C++11). You need to modify your makefile to use the -std=c++11 flag. If you post your makefile contents I could advise you further, otherwise look at this question: Makefile modification to support c++11

Based on the cmakefile posted, add these lines to your cmakefile:

set_property(TARGET abc PROPERTY CXX_STANDARD 11)
set_property(TARGET abc PROPERTY CXX_STANDARD_REQUIRED ON)