Jannat Arora
Jannat Arora

Reputation: 2989

Unrecognized command line in C++11

I compiled the following program but I don't know why am I getting the following error:

error: unrecognized command line option ‘-std=c++11’.

My gcc version is 4.6 and I have set c++ compiler in netbeans to 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;
}

Upvotes: 0

Views: 1167

Answers (2)

Jonathan Wakely
Jonathan Wakely

Reputation: 171383

Try reading the manual for GCC 4.6, which says you need to use -std=c++0x or -std=gnu++0x, see https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Standards.html

This is because GCC 4.6 was released before the C++11 standard was published.

You will need to adjust your Netbeans settings to use -std=c++0x instead of -std=c++11

Upvotes: 4

Alex Reynolds
Alex Reynolds

Reputation: 96976

Upgrade your GCC to something that supports modern C++11, like GCC 4.8 or greater.

Upvotes: 1

Related Questions