How can I compile C++11 code with Orwell Dev-C++?

19,638

Please make sure you supply the correct -std flag when compiling. The default setting that Orwell Dev-C++ uses (don't pass any -std option), will not enable some shiny new C++11 functions, like unique_ptr. The fix is quite simple:

  • For non-project compilations, go to: Tools >> Compiler Options >> (select your compiler) >> Settings >> Code Generation >> (set 'Language standard' to a C++11 option)
  • For project compilations, go to: Project >> Compiler >> Code Generation >> (set 'Language standard' to a C++11 option)

Here's a bit more information about the -std flag: http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

As you can see, GCC uses a GNU dialect of C++03 by default (which doesn't seem to support unique_ptr).

Share:
19,638
Fihop
Author by

Fihop

Updated on June 05, 2022

Comments

  • Fihop
    Fihop almost 2 years

    Trying to compile the following code:

    #include <iostream>
    #include <memory>
    
    struct Foo {
        Foo() { std::cout << "Foo::Foo\n"; }
        ~Foo() { std::cout << "Foo::~Foo\n"; }
        void bar() { std::cout << "Foo::bar\n"; }
    };
    
    void f(const Foo &foo)
    {
        std::cout << "f(const Foo&)\n";
    }
    
    int main()
    {
        std::unique_ptr<Foo> p1(new Foo);  // p1 owns Foo
        if (p1) p1->bar();
    
        {
            std::unique_ptr<Foo> p2(std::move(p1));  // now p2 owns Foo
            f(*p2);
    
            p1 = std::move(p2);  // ownership returns to p1
            std::cout << "destroying p2...\n";
        }
    
        if (p1) p1->bar();
    
        // Foo instance is destroyed when p1 goes out of scope
    }
    

    with Orwell Dev-c++ 5.3.0.3 yields the following error:

    'unique_ptr' is not a member of 'std'.

    How can I handle this?

  • Fihop
    Fihop over 11 years
    I have one more problem when selecting Language standard as GNU C++11, it gives me "unrecognized command line option "-std=c++0x"
  • Orwell
    Orwell over 11 years
    Try selecting the GNU C++ standard. Looks like I need to update the ISO C++11 flags to 'c++11' from 'c++0x'.
  • Strahd_za
    Strahd_za almost 11 years
    Have you been able to get this working ? I installed the latest Dev-C++ 5.4.2 , but still get "unrecognized command line option "-std=c++0x" errors when I try to enable c++11.