【问题标题】:Unrecognized command line in C++11C ++ 11中无法识别的命令行
【发布时间】:2015-06-29 09:37:52
【问题描述】:

我编译了以下程序,但不知道为什么会出现以下错误:

错误:无法识别的命令行选项“-std=c++11”。

我的 gcc 版本是 4.6,我已将 netbeans 中的 c++ 编译器设置为 c++11。

#include <cstdlib>
#include <algorithm>
using namespace std;

template<class T>
void parallel_sort(T* data, int len, int grainsize)
{
    if(len < grainsize) // Use grainsize instead of thread count so that we don't e.g. spawn 4 threads just to sort 8 elements.
    {
        std::sort(data, data + len, std::less<T>());
    }
    else
    {
        parallel_sort(data + len/2, len/2, grainsize); // No need to spawn another thread just to block the calling thread which would do nothing.

        std::inplace_merge(data, data + len/2, data + len, std::less<T>());
    }
}

int main(int argc, char** argv) {
    return 0;
}

【问题讨论】:

  • 试试-std=c++0x,gcc4.6可能太老了,不支持-std=c++11
  • 我相信4.7.1左右添加了它。
  • @chris, 4.7.0
  • @JonathanWakely,很酷,谢谢。我认为这比我在下学期上课时使用的版本(实际上是两个)小了一个。

标签: c++ c++11


【解决方案1】:

尝试阅读 GCC 4.6 的手册,上面说您需要使用 -std=c++0x-std=gnu++0x,请参阅 https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Standards.html

这是因为 GCC 4.6 是在 C++11 标准发布之前发布的。

您需要调整您的 Netbeans 设置以使用 -std=c++0x 而不是 -std=c++11

【讨论】:

    【解决方案2】:

    将您的 GCC 升级到支持现代 C++11 的版本,例如 GCC 4.8 或更高版本。

    【讨论】:

      猜你喜欢
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 2014-07-06
      • 2015-02-05
      • 2017-04-09
      • 2015-11-12
      相关资源
      最近更新 更多